Obtain Javascript array from a dygraph created with csv

589 views
Skip to first unread message

Rafa

unread,
Jun 3, 2010, 5:16:51 PM6/3/10
to dygraphs-users
Dygraph parses csv data in an array, so my question is, there's a way
to obtain this array to avoid a new csv parsing?

Rafa

unread,
Jun 4, 2010, 4:18:55 AM6/4/10
to dygraphs-users
I've found a way:

var data = new Array();
var g = new Dygraph(document.getElementById("chart"),"test.csv",{});
for(var i=0;i<g["rawData_"].length;i++)
{
data[i] = g["rawData_"][i];
}

I don't know if it's the best way but works.

Josep Llodrà Grimalt

unread,
Jun 4, 2010, 4:24:04 AM6/4/10
to rafa...@gmail.com, dygraphs-users
Yep, that works, but may be unsafe.

Remember you can always use the native format instead of CSV
(parsing is faster when using the native array, too).

http://danvk.org/dygraphs/tests/native-format.html

--
Yours sincerely,
Josep Llodrà.

Rafa

unread,
Jun 4, 2010, 7:24:03 AM6/4/10
to dygraphs-users
Yes I know, but csv data are given. Why unsafe?

On 4 jun, 10:24, Josep Llodrà Grimalt <jlg.h...@gmail.com> wrote:
> Yep, that works, but may be unsafe.
>
> Remember you can always use the native format instead of CSV
> (parsing is faster when using the native array, too).
>
> http://danvk.org/dygraphs/tests/native-format.html
>

Joshua Buss

unread,
Jun 4, 2010, 8:18:32 AM6/4/10
to dygraphs-users
Who is giving the CSV format? Surely someone came up with a script that generates this CSV? Simply create a json object instead of CSV and you should be good to go - this is what I've done. It's a bit more work to generate the data, but the parsing is much, much faster.

-Josh

Dan Vanderkam

unread,
Jun 4, 2010, 10:35:03 AM6/4/10
to rafa...@gmail.com, dygraphs-users
On Fri, Jun 4, 2010 at 4:24 AM, Rafa <rafa...@gmail.com> wrote:
> Yes I know, but csv data are given. Why unsafe?

The trailing underscore in "rawData_" indicates that it's a private
member of dygraphs. I may change its name or remove it entirely in a
future refactor. Your code will work now, but there's no reason to
think that it will work in the future.

- Dan

Rafa

unread,
Jun 4, 2010, 5:26:32 PM6/4/10
to dygraphs-users
The CSV format is given by a closed application. I'll investigate
about json object, thanks.


On 4 jun, 14:18, Joshua Buss <joshua.b...@gmail.com> wrote:
> Who is giving the CSV format? Surely someone came up with a script that
> generates this CSV? Simply create a json object instead of CSV and you
> should be good to go - this is what I've done. It's a bit more work to
> generate the data, but the parsing is much, much faster.
>
> -Josh
>

Rafa

unread,
Jun 4, 2010, 5:26:52 PM6/4/10
to dygraphs-users
The CSV format is given by a closed application. I'll investigate
about json object, thanks.


On 4 jun, 14:18, Joshua Buss <joshua.b...@gmail.com> wrote:
> Who is giving the CSV format? Surely someone came up with a script that
> generates this CSV? Simply create a json object instead of CSV and you
> should be good to go - this is what I've done. It's a bit more work to
> generate the data, but the parsing is much, much faster.
>
> -Josh
>
Reply all
Reply to author
Forward
0 new messages