I deal with multi-line diagrams in dimpleys and get a little stuck on multi-axis logic.
With the following data:
var data = [ {"Month":"01/2013", "Revenue":2000, "Profit":2000, "Units":4}, {"Month":"02/2013", "Revenue":3201, "Profit":2000, "Units":3}, {"Month":"03/2013", "Revenue":1940, "Profit":14000, "Units":5}, {"Month":"04/2013", "Revenue":2500, "Profit":3200, "Units":1}, {"Month":"05/2013", "Revenue":800, "Profit":1200, "Units":4} ]
I am trying to get a chart showing, by months, my income and my profit on the same y axis and my units on the secondary y axis.
In the code below, I managed to display 3 series. But the Profit series is not really on the same axis as revenue, and it all seems more like a hack than the right solution.
var chart = new dimple.chart(svg, data); chart.setBounds(60,20,680,330); var x = chart.addCategoryAxis("x", "Month"); var y1 = chart.addMeasureAxis("y", "Revenue"); chart.addSeries("null", dimple.plot.line, [x,y1]); var y2 = chart.addMeasureAxis("y", "Units"); chart.addSeries("null", dimple.plot.bar, [x,y2]); var y3 = chart.addMeasureAxis("y", "Profit"); chart.addSeries("null", dimple.plot.line, [x,y3]);
I guess my logic may be wrong in how to play with the series correctly. Any help would be great.
Thanks a lot, Xavier
Full code:
var svg = dimple.newSvg("body", 800, 400); var data = [ {"Month":"01/2013", "Revenue":2000, "Profit":2000, "Units":4}, {"Month":"02/2013", "Revenue":3201, "Profit":2000, "Units":3}, {"Month":"03/2013", "Revenue":1940, "Profit":14000, "Units":5}, {"Month":"04/2013", "Revenue":2500, "Profit":3200, "Units":1}, {"Month":"05/2013", "Revenue":800, "Profit":1200, "Units":4} ] var chart = new dimple.chart(svg, data); chart.setBounds(60,20,680,330); var x = chart.addCategoryAxis("x", "Month"); var y1 = chart.addMeasureAxis("y", "Revenue"); chart.addSeries("null", dimple.plot.line, [x,y1]); var y2 = chart.addMeasureAxis("y", "Units"); chart.addSeries("null", dimple.plot.bar, [x,y2]); var y3 = chart.addMeasureAxis("y", "Profit"); chart.addSeries("null", dimple.plot.line, [x,y3]); x.dateParseFormat = "%m/%Y"; x.addOrderRule("Date"); chart.draw();