Jurgen
Jurgen

Reputation: 311

FLOT unable to get x-axis properly

I've been struggling with this problem for a few days now and i cant seem to find what i am doing wrong (or not doing), so i've finally decided to open a topic, because this is driving me nuts, and i pressume its just an easy overlooked mistake.

//baroptions.xaxis.ticks = [[189, 'Wed 11h']];
//baroptions.yaxis.max = 200;

     baroptions.xaxis.ticks = [[0,'Wed 11h'], [1,'Wed 12h']];
baroptions.yaxis.max = 200;
 $.plot($("#poep"), [{
     data: [['Wed 11h', 100],['Wed 12h', 200]],
     label: 'Outgoing',
     bars: {show: true, barWidth: 0.5},
     color: "#00FF00"
     }], baroptions);

baroptions is valid, these options work when i change the data to match numeral data.

This above is just a random sample of data which will be populating the graph eventually its something like: wed 11h, wed 12h, wed 13h which are all strings. According to the FLOT api documentation, i have to use the ticks to specify them, however no data is shown in my graph. All examples on the FLOT page are either integers, or they use timed data (which this is aswell, essentially, however, a valid timestamp cannot be made from just time).

I hope someone can show what i am doing wrong here.

Upvotes: 0

Views: 134

Answers (1)

DNS
DNS

Reputation: 38189

The x-axis values themselves must always be numeric; the approach suggested in the docs only changes their labels. So to fix your example, you would need to use this:

data: [[0, 100], [1, 200]],

Here you're using numeric values, as Flot expects, while your 'ticks' option changes the tick labels for those values to your strings.

Another option is to use the new categories plugin that we added in 0.8.

Upvotes: 1

Related Questions