4

In jqPlot, I have two series rendered in the graph. They show different data, measured in different units, so they each have their own y-axis (yaxis and y2axis).

jqPlot constructs both y-axes automatically to suit the range of the data. That is ok - I don't want to set the axis min, max, ticks manually, as the range of the data may vary greatly.

However, I would like to align the 0 ticks for both y-axes to the same level. Is this possible?

Note: One may argue that there is no point to align, for example, 0° C temperature with 0 ms^-1 wind speed, as there is no mathematical relation between the values. But it does look a lot better if it is so, and looking good is the whole point of graphs :)

Testing example:

var data1 = [[0, 0], [3, 50]];
var data2 = [[0, 0], [3, -50]];

$.jqplot('chart', [data1, data2], {
  series: [
    { yaxis: 'yaxis' },
    { yaxis: 'y2axis' },
  ]        
});
Imp
  • 8,409
  • 1
  • 25
  • 36

1 Answers1

3

I think this is definitely a bug in jqplot.

See this three fiddles [1], [2] and [3]. The first one is extracted from the examples in the last release of jqplot. The second one, shows the default mode, with forceTickAt0 and alignTicks disabled. Finally, the third one is the same original one, but changing the second data value in the first series with a negative value.

You can see how the zeroes are aligned in the first example. In the third example, however, the axis don't align anymore although all settings remain the same.

You can try filing an issue for this in the jqplot issues page.

In the meantime, to solve your problem, you could work around this issue by adding an offset to the values so that all become positive and then rewrite the axis labels to show this offset difference. You can see an example here. However, I'm afraid this is still not exactly what you were trying to accomplish.

jbalsas
  • 3,484
  • 22
  • 25