0
votes

In jqplot, why is the auto scaling on bar charts so very different from on line charts?

Using the exact same data, I get these two plots:

enter image description here

enter image description here

The options I use for the two plots are:

var bar_options = {
axesDefaults: { labelRenderer: $.jqplot.CanvasAxisLabelRenderer },
seriesDefaults: { renderer: $.jqplot.BarRenderer, rendererOptions: { highlightMouseOver:false, barMargin:5, shadowOffset:1 } },
axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer }, yaxis: { tickOptions:{show:false} } },
};

and

var line_options = {
axesDefaults: { labelRenderer: $.jqplot.CanvasAxisLabelRenderer },
seriesDefaults: { rendererOptions: { smooth: true } },
axes: { xaxis: { min:1, max:30, tickInterval:1, pad:0 }, yaxis: { tickOptions:{show:false} } },
};

The line plot looks really good, but the bar chart is next to useless with the scaling shown.

Why is the default scaling so different between the two plots, and how can I get the scaling on the bar plot to be the same as the line graph?

EDIT:

I have created a simpler example, with data as follows:

[38.23, 39.33, 41.67, 40.21, 45.01, 44.47, 37.04]

And the resulting graph shown is this:

enter image description here

Adding a y-axis scale, shows that the data is starting from 0.

I changed my plot code to this...

var home_bar_options = {
axesDefaults: { labelRenderer: $.jqplot.CanvasAxisLabelRenderer },
seriesDefaults: { renderer: $.jqplot.BarRenderer, rendererOptions: { highlightMouseOver:false, barMargin:5, shadowOffset:1 } },
axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer }, yaxis: { min:30, max:50 } }
};

But the plot doesn't change, and completely ignores the 'min' and 'max' values that I have entered for the y-axis scale.

Why is this?

1

1 Answers

0
votes

I have not found any 'proper' way to move the axis on the bar chart, but I have managed to find a workaround.

My page is in PHP, and the data is coming from a mysql database.

So, after I have the data, and before I draw the bar chart plot, I get the minimum data value, and subtract that value from all my data!

So if my data is

35, 38, 36, 42, 40

I subtract 35 from all data, giving a new data set of

0, 3, 1, 7, 5

The bar chart will then plot this in a much better looking way!

Because I don't need to see actual data numbers, just the trend, this works ok for me - but wouldn't work if you needed a y-axis with a scale.

If anyone has a 'proper' way to properly adjust the bar plot y-axis away from zero, then I would be very happy to hear it!

But, for now, my workaround will suffice!