rickshaw icon indicating copy to clipboard operation
rickshaw copied to clipboard

Add/Remove series data

Open mzupan opened this issue 13 years ago • 11 comments

I'm looking to make a chart generator and I have no idea what type of data they will graph. I'm wondering if there is a way to add remove series data from a graph without a refresh or anything. So the line and item in the legend will just show up when there is a new series data added to the array.

I tried to just add it to like graph.series array but it never updated to reflect it.

mzupan avatar Jul 13 '12 22:07 mzupan

ok seems like it works.. it was an issue in the code.. only thing that doesn't update is the legend it seems when you append a new series to a graph

mzupan avatar Jul 14 '12 17:07 mzupan

@mzupan: I'd be interested to know how you achieved this...

I'm trying to do the same thing, and am stuck when I try to update the graph.series.

Here's a sample of code of what I'm trying to do:

var newSerie = {
        color : palette.color(),
        data  : data,
        name  : title
    };
graph.series.push(serie);

graph.validateSeries(graph.series);
graph.update();

These two last calls always throw errors...

I saw that the data is contained multiple times in the graph object:

  • graph.series[x].data
  • graph.stackedData

which makes me think I might not be updating the right one...

Any help would be appreciated...

Thanks,

gsejourne avatar Aug 03 '12 11:08 gsejourne

@gsejourne

see the following jsfiddle

http://jsfiddle.net/tWXzL/1/

mzupan avatar Aug 03 '12 13:08 mzupan

Yes but is it possible to start the chart without data, i.e. a 'chart skeleton', and add the data later?

radiodario avatar Aug 28 '12 15:08 radiodario

@radiodario

From what I tried, not out of the box no.

You gotta play a bit with the configuration: for instance, you must instantiate the legend, etc. once the data is there.

So the "blank" skeleton configuration will be limited to the minimum.

gsejourne avatar Aug 28 '12 15:08 gsejourne

Thanks a bunch! - is there an example?

radiodario avatar Aug 28 '12 15:08 radiodario

Using a slightly modified version of the jsfiddle, I display a legend box. The problem is that the legend is not dynamicaly updated when I add a serie.

http://jsfiddle.net/tWXzL/61/

Any idea?

Sephi-Chan avatar Dec 13 '12 15:12 Sephi-Chan

I handle this by emptying the legend element and creating a new legend:

$('#legend_container').empty();
legend = new Rickshaw.Graph.Legend({
    graph: graph,
    element: document.getElementById('legend_container')
});

I add this to the button's click handler: http://jsfiddle.net/tWXzL/62/

rouge8 avatar Dec 13 '12 15:12 rouge8

This issue should be properly fixed by pull request https://github.com/shutterstock/rickshaw/pull/266.

mpderbec avatar Jun 20 '13 19:06 mpderbec

Why not just call legend.render()? :)

adampl avatar Feb 11 '15 15:02 adampl

None of the fiddles work at the moment.

ceremcem avatar May 29 '19 17:05 ceremcem