Issue on Y axis range when I mix Line and Bar charts

Share RGraph:   Share or Like RGraph on Facebook!

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by arnaud on 6th February 2013
When I mix line and bar chart I have issue on Yaxis.

The range displayed is the one link with bar chart, thus line chart value are not at the right level.

I was expecting the chart will define a range compliant as well for the bar and the line.


Here is the code :

<div style="float:left" class="roundCorner"><canvas id="regulateur" width="430" height="270" ></canvas></div>

<script>
         var dataBar3 = [3561.478571,3555.578571,0,0,0,0,0,0,0,0,0,0];
var dataBar3Tooltip = ['3561.478571','3555.578571','0','0','0','0','0','0','0','0','0','0'];
var budgetRegulateur=3760.428571;
    var bar3 = new RGraph.Bar('regulateur', dataBar3);
          bar3.Set('chart.gutter.top', 35);
          bar3.Set('chart.gutter.left', 65);
          bar3.Set('chart.labels', xaxis);
          bar3.Set('chart.tooltips', dataBar3Tooltip);
          bar3.Set('hmargin', 2);
          bar3.Set('chart.title','Suivi de la consommation Regulateur');

          var dataLine3 = [];
          for (var i=1;i<=12;i++)
              dataLine3[i-1] = Math.round(budgetRegulateur*(1-i/12));

          var line3 = new RGraph.Line('regulateur', dataLine3);
          line3.Set('chart.linewidth', 3);
          line3.Set('chart.colors', ['green']);
          line3.Set('chart.tickmarks', 'circle');
          line3.Set('chart.tooltips', xaxis);
    line3.Set('chart.labels', xaxis);

          for (var i=0; i < dataBar3.length; ++i)
              line3.Get('chart.tooltips')[i] = xaxis[i] + ' - '+dataLine3[i];

          var combo3 = new RGraph.CombinedChart(bar3, line3);
          combo3.Draw();

</script>

Do you see why ?

regards,
Posted by RGraph support on 7th February 2013
Hi,

You can fix the Line maximum Y value with the chart.ymax option:

line3.Set('chart.ymax', bar3.max);

Additionally you'll probably then want to turn off the line chart Y labels with chart.ylabels=false and the axes with chart.noyaxis=true.




Richard
Posted by arnaud on 7th February 2013
In fact What I would expect is to get the same scale between Line and Bar chart. So forcing the yMax could be avoided by an embedded feature inside RGraph.CombinedChart calculating the scale and align line and bart to the scale ?
Posted by RGraph support on 7th February 2013
Hi,

Sometimes you want different scales.

Richard, RGraph Support
Posted by arnaud on 8th February 2013
Ok thank you for the solution

Add a reply




« Back to message list