extending time series charts with null data points [flotr from svn, rev 173]

6 views
Skip to first unread message

Faried Nawaz

unread,
Nov 12, 2010, 9:20:04 AM11/12/10
to Flotr Javascript Plotting Library
Hello,

I'm building a chart with stock market index data, captured during the
trading session. I want to always generate a chart for the entire
trading day -- 9am to 4pm. I've tried plotting a chart with live data
and then extending it like so:

# fill rest of the day with nulls during trading hours
if trading and rows:
maxtime = time.localtime(rows[-1]['entrytime'])
for hour in (10, 11, 12, 13, 14, 15):
if maxtime[3] < hour:
ls = list(maxtime)
ls[3] = hour
mk = time.mktime(tuple(ls))
plotls.append([int(mk) * 1000, None])
[...]
jsonstr = json.write({'title': '%s on %s' % (indexname, feed_date),
'data' : plotls })

I've verified that the Y-axis values in the JSON-encoded string are
null. My problem is that it leads to a chart that looks looks like it
goes to zero. Here are two images to demonstrate what I mean:
http://imgur.com/a/qc4WH

How can I make it look like the correct chart, but extended until the
end of the day?


Thanks,

Faried.

George Roberts

unread,
Nov 12, 2010, 10:40:21 AM11/12/10
to fl...@googlegroups.com
> http://imgur.com/a/qc4WH

If you want to extend horizontally then it should be easy. Instead of
adding nulls to the end, remove them from the end with a for loop (or don't
add them) and add a single point at xaxis.max with the same y value as the
final valid trade.

I think it would look better with no graph when there is no trading.
Unfortunately there seems to be a bug with the "fill" feature. It should
fill straight down, not at an angle like that. just past the 16:06 tick.
Did you try doing the exact same graph with no fill? I think it would look
better that way (with your nulls) then extending the closing time straight
out horizontally.

- George Roberts
http://gr5.org

--------------------------------------------------
From: "Faried Nawaz" <far...@gmail.com>
Sent: Friday, November 12, 2010 9:20 AM
To: "Flotr Javascript Plotting Library" <fl...@googlegroups.com>
Subject: extending time series charts with null data points [flotr from svn,
rev 173]

> --
> You received this message because you are subscribed to the Google Groups
> "Flotr Javascript Plotting Library" group.
> To post to this group, send email to fl...@googlegroups.com.
> To unsubscribe from this group, send email to
> flotr+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/flotr?hl=en.
>

Faried Nawaz

unread,
Nov 12, 2010, 11:43:32 AM11/12/10
to Flotr Javascript Plotting Library
On Nov 12, 8:40 pm, "George Roberts" <gr-googlegrp...@spamarrest.com>
wrote:

> If you want to extend horizontally then it should be easy.  Instead of
> adding nulls to the end, remove them from the end with a for loop (or don't
> add them) and add a single point at xaxis.max with the same y value as the
> final valid trade.

I thought about doing that, but didn't try it out. I'll try it and
see how it looks on Monday.


> I think it would look better with no graph when there is no trading.
> Unfortunately there seems to be a bug with the "fill" feature.  It should
> fill straight down, not at an angle like that.   just past the 16:06 tick.
> Did you try doing the exact same graph with no fill?  I think it would look
> better that way (with your nulls) then extending the closing time straight
> out horizontally.

I'll experiment with that.


Thanks!

Faried.

Faried Nawaz

unread,
Nov 16, 2010, 4:27:59 AM11/16/10
to Flotr Javascript Plotting Library
On Nov 12, 8:40 pm, "George Roberts" <gr-googlegrp...@spamarrest.com>
wrote:

> If you want to extend horizontally then it should be easy.  Instead of
> adding nulls to the end, remove them from the end with a for loop (or don't
> add them) and add a single point at xaxis.max with the same y value as the
> final valid trade.

I ended up doing this, with no fill. With nulls and no fill, it still
looked pretty bad -- the Y axis scaled from 0 to 10k (the current
index level).


Faried.

George Roberts

unread,
Nov 16, 2010, 9:16:30 AM11/16/10
to fl...@googlegroups.com
So now you don't like that Y axis goes to 0? Is that the problem? I don't
understand but if that's the problem then you can set yaxis.min to any value
you want in options. That way you can "zoom" in on the data better.

The pictures you posted before were clear as to the problem - the fill was
bad. Obviously if there is no fill, then there is no bad fill problem.

- George Roberts
http://gr5.org

--------------------------------------------------
From: "Faried Nawaz" <far...@gmail.com>

Sent: Tuesday, November 16, 2010 4:27 AM


To: "Flotr Javascript Plotting Library" <fl...@googlegroups.com>

Subject: Re: extending time series charts with null data points [flotr from
svn, rev 173]

> On Nov 12, 8:40 pm, "George Roberts" <gr-googlegrp...@spamarrest.com>


> wrote:
>
>> If you want to extend horizontally then it should be easy. Instead of
>> adding nulls to the end, remove them from the end with a for loop (or
>> don't
>> add them) and add a single point at xaxis.max with the same y value as
>> the
>> final valid trade.
>

> I ended up doing this, with no fill. With nulls and no fill, it still
> looked pretty bad -- the Y axis scaled from 0 to 10k (the current
> index level).
>
>

Faried Nawaz

unread,
Nov 18, 2010, 7:02:01 PM11/18/10
to Flotr Javascript Plotting Library
On Nov 16, 7:16 pm, "George Roberts" <gr-googlegrp...@spamarrest.com>
wrote:
> So now you don't like that Y axis goes to 0?  Is that the problem?

That's actually the problem I've had all along. That's why I tried
nulls for the Y-axis values instead of 0.00 -- I didn't want it to go
to zero.


> The pictures you posted before were clear as to the problem - the fill was
> bad.  Obviously if there is no fill, then there is no bad fill problem.

In my original post, I didn't mention a fill problem.

I need to draw a chart with X-axis ticks that go to 4pm no matter what
time of the day it is. That's why I'm extending the chart.


Faried.

George Roberts

unread,
Nov 18, 2010, 7:51:16 PM11/18/10
to fl...@googlegroups.com
> I need to draw a chart with X-axis ticks that go to 4pm no matter what
> time of the day it is. That's why I'm extending the chart.

Oh!!!! Then all you need do is set xaxis.max=4pm;

If you specify xaxis.max then it will extend the xaxis out to that value.
The line won't go out to 4pm but the background grid will.

Well that's not the syntax exactly. You need to convert 4pm for that day
into a proper time value (milliseconds since jan 1, 1970) which should be
pretty easy in javascript.

- George Roberts
http://gr5.org

--------------------------------------------------
From: "Faried Nawaz" <far...@gmail.com>

Sent: Thursday, November 18, 2010 7:02 PM


To: "Flotr Javascript Plotting Library" <fl...@googlegroups.com>
Subject: Re: extending time series charts with null data points [flotr from
svn, rev 173]

> On Nov 16, 7:16 pm, "George Roberts" <gr-googlegrp...@spamarrest.com>


> wrote:
>> So now you don't like that Y axis goes to 0? Is that the problem?
>

> That's actually the problem I've had all along. That's why I tried
> nulls for the Y-axis values instead of 0.00 -- I didn't want it to go
> to zero.
>
>

>> The pictures you posted before were clear as to the problem - the fill
>> was
>> bad. Obviously if there is no fill, then there is no bad fill problem.
>

> In my original post, I didn't mention a fill problem.
>
>
>

Faried Nawaz

unread,
Nov 24, 2010, 5:38:28 AM11/24/10
to Flotr Javascript Plotting Library
On Nov 19, 5:51 am, "George Roberts" <gr-googlegrp...@spamarrest.com>
wrote:

> Oh!!!!  Then all you need do is set xaxis.max=4pm;

That did the trick. Thanks. I wrote a function to do something like

var d = new Date();
var setaxis = null;

if (d.getHours() > 8 && ... some other stuff ...) {
d.setHours(16);
d.setMinutes(35);
setaxis = d.getTime();
}
if (setaxis) flotroptions.xaxis.max = setaxis;


Faried.
Reply all
Reply to author
Forward
0 new messages