time series chart -- skipping days [svn rev 173]

16 views
Skip to first unread message

Faried Nawaz

unread,
Nov 25, 2010, 7:39:30 AM11/25/10
to Flotr Javascript Plotting Library
Hello,

I'd like to skip "empty" days. For example, if I plot this:

[[1289415600000,1960262],
[1289502000000,489297],
[1289761200000,146124],
[1289847600000,2406706],
[1290366000000,500643],
[1290452400000,1698707],
[1290538800000,3138513],
[1290625200000,314310]]

I get

http://imgur.com/RUmDX.png

It plots the days between the timestamps in my data -- weekends,
holidays, etc. How can I avoid this, while still using mode: 'time'?
I looked at the code, but didn't see any easy way to modify it to do
what I want.

I tried switching to mode: 'normal' and setting my own ticks, but that
led to a different problem -- a dense X-axis where none of the labels
were legible when I tried to plot a year's worth of data.


Faried.

Faried Nawaz

unread,
Nov 25, 2010, 8:18:24 AM11/25/10
to Flotr Javascript Plotting Library
I switched to mode: 'normal', and wrote my own x-axis tick formatter.
The result is the same, pretty much: http://imgur.com/tAPkM.png


Faried.

Faried Nawaz

unread,
Nov 29, 2010, 8:28:45 AM11/29/10
to Flotr Javascript Plotting Library
Here's how I solved this. It was pretty obvious, once I took a break
from the keyboard for a short while.

I have my server-side code generate two JS expressions:

var currentplot = [[0,19.230000],[1,19.550000],[2,19.700000],
[3,19.870000],[4,19.630000],[5,19.600000],[6,19.530000],
[7,19.370000]];
xaxis = ["Nov 15 2010","Nov 16 2010","Nov 22 2010","Nov 23 2010","Nov
24 2010","Nov 25 2010","Nov 26 2010","Nov 29 2010"];

Options:

var currentopts = {xaxis: {labelsAngle: 45, tickFormatter:
xaxisformatter},
yaxis: {autoscaleMargin: 1.1},
mouse: {track: true, trackFormatter:
currentformatter, trackDecimals: 2}};

Formatters:

function xaxisformatter(t)
{
return xaxis[parseInt(t, 10)];
}

function currentformatter(loc)
{
var datestr = xaxisformatter(loc.x);
var price = loc.y;
// volumeplot is the data for another chart on the page
var volume = volumeplot[loc.x - 1][1];

return '(' + datestr + ' Price: ' + price + ' Volume: ' + volume +
')';
}
Reply all
Reply to author
Forward
0 new messages