Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not create Dygraph object with null or empty data #597

Closed
mKlus opened this issue Apr 21, 2015 · 23 comments
Closed

Can not create Dygraph object with null or empty data #597

mKlus opened this issue Apr 21, 2015 · 23 comments
Assignees

Comments

@mKlus
Copy link

mKlus commented Apr 21, 2015

It would be nice if we could create Dygraph object without passing in any data (null) or alternatively empty array ([]).

This would allow us to create the Dygraph object first and pass data to it only when we receive them from server etc.

I ended up modifying the start_ function and added the following check

if (data == null) {
return;
}

I also tried passing in empty array but that logs an error:
"Can't plot empty data set"

@danvk
Copy link
Owner

danvk commented Apr 22, 2015

I don't want to support null as that's as likely to be a configuration error as a request to plot an empty chart.

You can get an empty chart by plotting a CSV file with no data, e.g.

new Dygraph(document.getElementById("graph"), "X\n", {});

See http://jsfiddle.net/eM2Mg/6033/

@danvk
Copy link
Owner

danvk commented Apr 22, 2015

If you're set on using native format, you could also do something like:

g = new Dygraph('graph', [[0]], {labels:['X']});

I could be more easily convinced that [] should be a valid input than null.

@mKlus
Copy link
Author

mKlus commented Apr 22, 2015

We don't have the labels, neither we know how many series there will be when creating the Dygraph object.

For me it doesn't make sense to construct Dygraph with temporary data and labels.

Can we perhaps agree on the below being a valid code then? :-)

g = new Dygraph('graph', [], {labels:[]});

@markzolotoy
Copy link

So, what's is the solution to set graph's data after it's been returned by the server?

@danvk
Copy link
Owner

danvk commented May 8, 2015

@markzolotoy you just do g.updateOptions({file: ...}). I don't see what that has to do with this issue.

@blankclemens
Copy link

+1 for this request - right now my solution would be to create a graph with a single point, which I will remove the first time real data is added. Quite some lines of code for no real reason.

['NaN', 'NaN'] seems like a predestinated point to solve this issue, however drawing the graph doesn't work if this is the first entry.
[0, 'NaN'] is nearly perfect, but then the graph will always start from 0.

@vasanthps
Copy link

+1 for this request. Empty array makes more sense than null.

Thanks,
Vasanth

@LaughDonor
Copy link

I just have my data points set to [[startX],[endX]] value and it shows the graph with the X Range specified where I want to show.

@eddified
Copy link

I'd like this feature, too. Seems that [] still isn't accepted.

@timematcher
Copy link

could really use [] as initialization parameter. Kindly add support for it..

@erazor83
Copy link

+1 for

    g = new Dygraph('graph', [], {labels:[]});

@mmek123
Copy link

mmek123 commented Dec 21, 2016

new Dygraph(document.getElementById("graph"), "X\n", {});

I used the above . but why does it show a "11:00" as the x axis start value.

How can i get a blank graph may be start with 0 on X

tx

@angrybirdnut
Copy link

What if I want to redraw the the dygraph plot, is there a way to do so? When I obtain new data from the server, I want the existing plot to be cleared and redrawn with the new data. I currently use the follwing method updateOptions( { 'file': data } ); but all it does is to add the new data to the previous data and displays both on the plot.

@danvk
Copy link
Owner

danvk commented Jan 4, 2018

@angrybirdnut g.updateOptions({file: newData}) should clear the old data and plot the new. If you can post a reproduction of this not happening (e.g. via dygraphs.com/fiddle) then you've found a bug!

@angrybirdnut
Copy link

@danvk : Thanks, i took another look at my JS code and it turns out the issue was actually with my code (an array I was using was incorrectly concatenating all new data coming in from the server with the existing data). I have resolved it and g.updateOptions({file: newData}) is working well as intended.

@J-Rojas
Copy link
Contributor

J-Rojas commented Apr 24, 2019

It's 2019 and an empty array throws an error :-\ There should be support for a graph with no data since the data could be provided at a later time. I'm pretty sure people have forked this library simply to remove this check. Is this library being maintained?

@danvk
Copy link
Owner

danvk commented Apr 24, 2019

See #727. I'm not actively working on dygraphs and have no plans to resume doing so. If anyone is interested in taking ownership, I'm happy to share the commit bit.

As for this issue itself, I'd be fine with [] showing an empty plot.

@przmv przmv self-assigned this Apr 24, 2019
@przmv
Copy link
Collaborator

przmv commented Apr 24, 2019

Ok, I'll implement showing an empty plot when [] is provided as the input data.

@prahthana
Copy link

How to create data set for multiple series? I have multiple labels and need an empty set to be initialized

@armsp
Copy link

armsp commented Oct 12, 2019

+1 for the same.
@pshevtsov any updates on this?

@armsp
Copy link

armsp commented Oct 13, 2019

Currently I use this hack -

var flag = 50; //the number of empty/0/null data points you are forced to initialize
if (flag>0){
  flag-=1;
  data.shift();
  data.push([x, y, z, w]);
}
else{
  data.push([x, y, z, w]);
}

@armsp
Copy link

armsp commented Oct 17, 2019

But the above doesn't work well because of the timestamp issue. As the initial points are plotted based on time that is calculated at the start of the script, when a certain amount of time passes before your dynamic data starts coming in, there is a very ugly stretch of the plot at the beginning.

I don't know how to avoid that.

@mirabilos
Copy link
Collaborator

I’ve implemented the [] syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests