How to show values above bars in a dojox columns chart - charts

Is there any way to show the y-value of every bar above the actual bar in a dojox columns-type chart? Here's my code (which I got from http://glenurban.me.uk/A55D03/Blog.nsf/dx/DojoChart.htm):
<script type="text/javascript">
dojo.require("dojox.charting.Chart2D");
var series1 = [ 3, 2, 5, 3, 6, 4];
var xlabels = [
{value : 1, text : "a"},
{value : 2, text : "b"},
{value : 3, text : "c"},
{value : 4, text : "d"},
{value : 5, text : "e"},
{value : 6, text : "f"},
{value : 7, text : "g"}];
var chart1;
makeCharts = function() {
chart1 = new dojox.charting.Chart2D("simplechart");
chart1.addPlot("default", {
type : "Columns",
gap : 2
});
chart1.addAxis("x", {
labels : xlabels
});
chart1.addAxis("y", {
vertical : true,
min : 0
});
chart1.addSeries("Series1", series1);
chart1.render();
};
dojo.addOnLoad(makeCharts);
</script>

Unfortunately, it looks like this is a feature that still hasn't been included into the later versions of Dojo: see ticket, and this ticket (found from this mailing list.)
I've tried checking to see if there is a way to use Dojo GFX to get the values from your series of data... and then overlay that on to the chart. But, doing labels that way is going to be kludgy (and this all depends on if Dojo GFX's surface allows for a surface overlay on a SVG chart object already created.)
There's always the option to add this functionality in to the Dojo Chart2D library itself. But whenever you do that, unless you are able to get your patches changed with the main Dojo Chart2D branch, you'll want to be careful not to overwrite your custom-made library with a newer version of Chart2D in the future.
However, if you aren't stuck to Dojo for this particular need, have you considered using jQuery? There are many different chart/graph libraries out there, these days:
Highcharts (examples)
Flot (examples)
Tuftegraph (examples)
Also, Google Chart Tools is pretty nice, if jQuery isn't your thing.
Or... JavaScript InfoVis Toolkit is great, as well.

For information, it's now possible to have columns chart with label. For exemple :
addPlot("default", {type: "ClusteredColumns", labels: true,labelStyle:"outside" or "inside" })

Related

Default select first bar of viz column graph when page loads in sapui5

I have used viz chart library. I have given some drill down functionality on the column graph. For that I have to select any column of the graph to see the detail for the selected part (in the same page).
Now I want to select my first column/bar of the column graph automatically. It means when I go to the graph page, the first bar should be selected as default and the detail of the selected bar should be there.
Please help me guys.
Code:
View:
<viz:ui5.Column id="chart" selectData="goToDaily" width="auto">
<viz:plotArea>
<viz:ui5.types.VerticalBar colorPalette="#FFCC00"/>
</viz:plotArea>
<viz:title>
<viz:ui5.types.Title text="Monthly">
</viz:ui5.types.Title>
</viz:title>
<viz:dataset>
<viz:ui5.data.FlattenedDataset id="fds1" >
<viz:dimensions>
<viz:ui5.data.DimensionDefinition id="dim" axis="1" name="Month" value="{name}">
</viz:ui5.data.DimensionDefinition>
</viz:dimensions>
<viz:measures>
<viz:ui5.data.MeasureDefinition id="mea" name="Values" value="{value}">
</viz:ui5.data.MeasureDefinition >
</viz:measures>
</viz:ui5.data.FlattenedDataset>
</viz:dataset>
</viz:ui5.Column>
Controller:
Oninit:
JSONmodel = new sap.ui.model.json.JSONModel();
data1 = [ {
name : "Jan",
value : 100,
},
{
name : "Feb",
value : 150,
},
{
name : "March",
value :120,
},
{
name : "April",
value : 200,
}
];
JSONmodel.setData(data1);
sap.ui.getCore().byId("idPage3--chart").setModel(JSONmodel);
Select Data for Chart:
goToDaily:function(evt){
sap.ui.getCore().byId("idPage3--chart").selection({ctx:[{dii_a1:1}]});
}
I have tried to select month Feb as default selection, but not able to select it.
Regards,
Niket Talati
There are quite a few things incorrect in your code
You have specified an event handler for selectData but this is obviously only triggered when you first "select data". You never fire an event for data selection in your code, so the event handler will only be triggered if you click on a column manually
It seems you tried to fire the event from the event handler (which is the other way around, see previous point), but you have never implemented the fireSelectData method.
In addition, the signature of the map you tried to select is incorrect. According to the API (which is ill-formatted, I know) you need to send a whole lot more, something like this:
// ...snip...
var oSelection = {
data : [
{
target : oRect,
data : [
{
ctx : {
path : {
dii_a1 : 0,
dii_a2 : 0,
mg : 0,
mi : 0
},
type : "Measure"
},
val : 100
}
]
}
],
name : "selectData"
};
oYourChart.fireSelectData(oSelection);
// ...snip...
If you need to get an element by it's Id when using XMLViews, you should use this.getView().byId("chart") instead
Hope the above helps!

dimple.js: unequal time periods and missing labels

I have a date data series with uneven periods between data points. I want to have a label for each data point in the series. Any ideas how to archieve it?
Fiddle link is here
Just to promote my comment to an answer, one way to accomplish your mission would be to employ d3 axis to more rigidly control the axis. I updated John's jsfiddle here to demonstrate how we can do this. The full standalone code is below and in this gist.
<div id="volumeReport">
<script>
var svg = dimple.newSvg("#volumeReport", 590, 500);
var data = [
{"Date": "22/7/2014", "Volume" : 0},
{"Date": "15/11/2014", "Volume" : 1000},
{"Date": "5/01/2015", "Volume" : 2000},
{"Date": "5/2/2015", "Volume" : 3000},
{"Date": "31/3/2015", "Volume" : 4000}
];
var myChart = new dimple.chart(svg, data);
myChart.setBounds(60, 30, 510, 305)
var x = myChart.addTimeAxis("x", "Date", "%d-%m-%Y %H:%M:%S:%L", "%d-%m-%Y");
x.addOrderRule("Date");
x.timeField = "Date";
x.dateParseFormat = "%d/%m/%Y";
myChart.addMeasureAxis("y", "Volume");
var s = myChart.addSeries(null, dimple.plot.area);
s.interpolation = "step";
s.lineWeight = 1;
s.lineMarkers = true;
myChart.draw();
myChart.axes[0].shapes.call(
d3.svg.axis()
.orient("bottom")
.scale(myChart.axes[0]._scale)
.tickValues(data.map(function(d,i){
return d3.time.format("%d/%m/%Y").parse(d.Date)
})
)
.tickFormat(d3.time.format("%d-%m-%Y"))
)
</script>
</html>
A category axis will evenly space the dates along the axis:
myChart.addCategoryAxis("Date");
It also looks like you were trying to use a step area chart which requires version 2.1 of dimple. I've updated the version in the fiddle:
http://jsfiddle.net/tf3Sk/1/

Wavemaker using MouseZoomAndPan

In wavemaker a got an app that display charts with dojo charting, some charts have a lot
data so the chart is compressed so i look around and found that we could add zooming and panning, found an example on the web link:http://informatik.fh-brandenburg.de/~porebskk/dojo.html
i look at the source code and it looks like i only had to add this to my code
dojo.require("dojox.charting.action2d.MouseZoomAndPan");
and then call it before rendering the chart
new dojox.charting.action2d.MouseZoomAndPan(chart, "default");
My problem is when i had this to my source code
dojo.require("dojox.charting.action2d.MouseZoomAndPan");
and run the app i get "page Main as error" and my application does not work anymore
if i do this then my application comesback to life
//dojo.require("dojox.charting.action2d.MouseZoomAndPan");
i create a new application and i only had this on top of the main page and get
the error again
dojo.require("dojox.charting.action2d.MouseZoomAndPan");
in the wavemaker debugger i get "error parsing pages/Main/Main.js"
I am using AMD style but this may help you. I was able to find the missing piece with your link.
Dojo toolkit had some slightly incorrect code here (MouseZoomAndPan section), but it will give you the code I have below and is why I have commented out code after MouseZoomAndPan(...);
define(["dojox/charting/themes/Claro", "dojox/charting/Chart", "dojox/charting/axis2d/Default"
, "dojox/charting/plot2d/Lines", "dojox/charting/action2d/MouseZoomAndPan"],
function (claro, Chart, Default, Lines, MouseZoomAndPan) {
return {
createZoomableChart: function () {
"use strict";
var chart = new Chart("mouseZoom");
chart.addAxis("x", { type: Default, enableCache: true })
.addAxis("y", { vertical: true })
.addPlot("default", { type: Lines, enableCache: true })
.addSeries("Series A", [1, 2, 2, 3, 4, 8, 6, 7, 5]);
var mzap = new MouseZoomAndPan(chart, "default");//, { axis: "x", "none" });
chart.render();
},
init: function() {
this.createZoomableChart();
}
};
});

Highstock From/To Invalid Date Issue

I have got an issue in trying to generate a graph which has a "Price" axis, and one for "Volume", similar to that in the example given on the Highstock website. It displays the volume axis just fine, but not the prices.
In trying to determine the cause of the issue, I have disabled the volume, and upon doing so, the "From" and "To" rects at the top right both indicate "Invalid Date", yet they have been on the same format, epoch by millisecond, as the volume.
So here is my setup:
chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
alignTicks: false
},
rangeSelector: {
selected: 1
},
title: {
text: 'Price Graph'
},
yAxis: [{
title: {
text: 'Prices'
},
height: 200,
lineWidth: 2
}],
series: [
seriesOptions
]
});
And here is the "data" for the seriesOptions:
[[1362434092000, 20.3],
[1362434093000, 13.1],
[1362434199000, 7.01],
[1362434200000, 9.4],
[1362434796000, 7.23],
[1362434797000, 22.4],
[1362434798000, 13.1],
[1362434835000, 9.9],
[1362435142000, 9.2],
[1362435399000, 6.4],
[1362435400000, 13.5],
[1362435401000, 24.8],
[1362435453000, 6.4]]
UPDATE
Not sure if this will be of help, but found on line 292, it looks like it is failing here:
this[a+"Input"].value=xa(c.inputEditDateFormat||"%Y-%m-%d",this[a+"Input"].HCTime);
The HCTime here is undefined, so on line 20, where this function is defined:
xa=function(a,b,c){if(!s(b)||isNaN(b))return"Invalid date";
Hope this helps...
UPDATE 2
With the information in the variable seriesOptions, I tried to bring things to basics, and updated the series to be the following:
series : [{
lineWidth : 2,
marker : {
enabled : true,
radius : 2
},
shadow : true,
tooltip : {
valueDecimals : 2
},
type: 'line',
name : 'Test',
pointInterval : 15 * 1000,
data : [
[[1362434092000, 20.3],
[1362434093000, 13.1],
[1362434199000, 7.01],
[1362434200000, 9.4],
[1362434796000, 7.23],
[1362434797000, 22.4],
[1362434798000, 13.1],
[1362434835000, 9.9],
[1362435142000, 9.2],
[1362435399000, 6.4],
[1362435400000, 13.5],
[1362435401000, 24.8],
[1362435453000, 6.4]
]]
}]
This has a bit of a different outcome, one that I hope can help someone know what the problem is exactly - it also produces an empty graph space, but the "From" and "To" both say "Jan 1, 1970". An improvement from "Invalid Date", but still, doesn't make sense to me when the Epoch Converter website shows the correct translation of Tuesday, 5 March 2013 8:54:52 AM. -- What does this all mean?
UPDATE 3
This question has been up for a little while now, and I've received a hit-and-run -1 score which I'm not sure why I deserve. So to help explain a little more, I have made the following two screen shots:
Graph Image
JS Breakpoint with values
I hope this helps... It's driving me insane, and the research I've done suggests only to make sure the epoch timestamp is in Milliseconds.
Will be very, very grateful for help to this riddle - am almost finished this phase of the project, and it's been a long time coming.
Cheers.
Problem solved.
The main issue was that chart = new Highcharts.StockChart({ was being called twice in the script, before each attempt the contents of the container were being removed. On the first iteration, it had data to work with, the second time, it did not. Hence, NaN on the data.
Second issue, seriesOptions was itself an array, so foolishly I was making the series: an array of arrays.
I do have a unusual issue with the slider overlapping the volume axis, but I'll figure that out.

HighCharts Display Marker Value

Is there any way we can enable highcharts to display marker value at all the times ?
I got it working. Posting for reference of others
plotOptions : {
line : {
dataLabels : {
enabled : true,
formatter : function() {
return this.y + '%';
}
}
},
series : {
name : 'Team Briefing',
shadow : false,
marker : {
lineWidth : 2,
radius : 6,
symbol : 'circle'
}
}
},
Check the Point Marker reference guide. What I remember about Highcharts is that still it does not provide anything such as.
when you initiate the chart with an object (as your first argument) : ' ...new Highcharts.Chart( { ... } )'
one of this object properties you can use is the plotOptions.series.marker
this marker is an object itself:
marker:{
enabled:true,
lineWith:0.0,
radius:0.0,
// more attributes...
}
those are the default setting. meaning: It is enabled by default, but the radius is also zero by default, and that is the reson you don't see the points .
make a long story short: you need to set the raduis (to be bigger than zero)
read more at http://api.highcharts.com/highcharts#plotOptions.series.marker.radius