Periodic update from csv file

278 views
Skip to first unread message

Stefan Herrmann

unread,
Dec 21, 2011, 8:08:08 AM12/21/11
to dygraphs-users
Hi there.

I wanted to create a plot that is updated every few seconds. But the
resulting plot won't change when a add or remove or change data in the
given csv file. What am I doing wrong?

Here is the example:

<div id="graphdiv2" style="width:500px; height:300px;"></div>
<script type="text/javascript">
g2 = new Dygraph(document.getElementById("graphdiv2"),
"temperatures.csv", {} );
setInterval( function()
{
g2.updateOptions({file: "temperatures.csv"})
}, 2000);
</script>

Dan Vanderkam

unread,
Dec 22, 2011, 12:37:22 AM12/22/11
to stefan.h...@googlemail.com, dygraphs-users
I wonder if your browser is caching the results of "temperatures.csv"?
If it's constantly changing, maybe you could do something like:

setInterval( function()
{
g2.updateOptions({file:
"temperatures.csv?" + new Date().getTime()})
}, 2000);

- Dan

Stefan Herrmann

unread,
Dec 23, 2011, 3:26:14 AM12/23/11
to dygraphs-users
Yes you were right, the browser was causing the problem. I no fetch
the data via a XMLHTTPRequest and it works:

if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
{
var request = new XMLHttpRequest();
}
else // code for IE6, IE5
{
var request = new ActiveXObject('Microsoft.XMLHTTP');
}

request.open('GET', "temperatures.csv", false);
request.setRequestHeader("If-Modified-Since", new Date(0));
request.send();
if (request.status == 200)
{
// plot data
}

Glenn Trewitt

unread,
Dec 23, 2011, 4:28:38 PM12/23/11
to stefan.h...@googlemail.com, dygraphs-users
Would it make sense for dygraphs to handle this case, so that it "just works"?
    - Glenn
--

    - Glenn


Dan Vanderkam

unread,
Dec 23, 2011, 4:30:24 PM12/23/11
to glenn....@gmail.com, stefan.h...@googlemail.com, dygraphs-users
Well, most of the time you do want to hit the browser cache. What are
your proposing? If you do an updateOptions w/ the same file as before,
that it explicitly avoids the cache?

- dan

Glenn Trewitt

unread,
Dec 23, 2011, 4:34:55 PM12/23/11
to Dan Vanderkam, stefan.h...@googlemail.com, dygraphs-users
On Fri, Dec 23, 2011 at 1:30 PM, Dan Vanderkam <dan...@gmail.com> wrote:
Well, most of the time you do want to hit the browser cache. What are
your proposing? If you do an updateOptions w/ the same file as before,
that it explicitly avoids the cache?

Well, yes.  Why else would someone do an updateOptions on the file?
   - Glenn
 

Robert Konigsberg

unread,
Dec 23, 2011, 4:55:48 PM12/23/11
to glenn....@gmail.com, Dan Vanderkam, stefan.h...@googlemail.com, dygraphs-users
Could be because they're reusing an old set of options. But if they're being inefficient, well, that's their loss.

It's not such a bad idea.
--
Robert Konigsberg | Google NY | http://go/monarch

Glenn Trewitt

unread,
Dec 24, 2011, 9:38:35 PM12/24/11
to Robert Konigsberg, Dan Vanderkam, stefan.h...@googlemail.com, dygraphs-users
On Fri, Dec 23, 2011 at 1:55 PM, Robert Konigsberg <konig...@google.com> wrote:
Could be because they're reusing an old set of options. But if they're being inefficient, well, that's their loss.

It's not such a bad idea.
Sounds like, right now, you treat all options as affecting local state. Perhaps add a different "refresh" method to do this sort of thing.

I have a related question:  Is it possible to display two different inputs (csv files, for example) in the same graph?

I'd assume that that might break (what I assume to be a requirement) that all data points share the same time-values.  But I don't know, so I'm asking.

My purpose in asking is the notion of compositing timeseries:  If I have a several different timeseries, in groups, I might want to display group 1 and group 5 at the outset, and then switch to group 1 and 3.   Right now, AFAIK, my best option is to load up the data for all groups, and show only the ones that I want right now.  But, I may rarely or (almost) never want some of the groups.

    - Glenn

Dan Vanderkam

unread,
Dec 24, 2011, 10:36:52 PM12/24/11
to Glenn Trewitt, Robert Konigsberg, stefan.h...@googlemail.com, dygraphs-users
You have to do the merging of csv files yourself. I'm skeptical that this is something dygraphs should do.

The requirement of overlapping x-values isn't so stringent. See http://dygraphs.com/tests/independent-series.html for more.

There is some notion of options which do not affect data. Setting strokeWidth will not recompute the chart layout, for instance.

  - Dan

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages