8 thoughts on “Adding and removing data in v2

  1. @IonutLaceanu you could do something like

    function moveChart(chart, newData) {
        chart.data.labels.push('new label'); // add new label at end
        chart.data.labels.splice(0, 1); // remove first label
    
        chart.data.datsets.forEach(function(dataset, index) {
            dataset.data.push(newData[index]); // add new data at end
            dataset.data.splice(0, 1); // remove first data point
        });
    
        chart.update();
    }
  2. Ah, ok. I understand now.

    I think if you do all the removes, then call update then do all the adds then call update again it might be closer.

    function moveChart(chart, newData) {
        chart.data.labels.splice(0, 1); // remove first label
        chart.data.datsets.forEach(function(dataset) {
            dataset.data.splice(0, 1); // remove first data point
        });
    
        chart.update();
    
        // Add new data
        chart.data.labels.push('new label'); // add new label at end
        chart.data.datsets.forEach(function(dataset, index) {
            dataset.data.push(newData[index]); // add new data at end
        });
    
        chart.update();
    }
  3. Hi, I’m pretty new to chart.js and we’re looking to use it in our product. This feature was very nice in 1.0 and I think it’s a pretty big regression to not support it in 2.0.

    I’ve tried putting in the moveChart() function, but it really isn’t the same. It redraws the entire chart which makes it look like it’s all new data instead of just new data coming in at the end.

    I hope this can be looked into further for the 2.0 stream as it really is a great feature.

  4. As it was mentioned before, this is huge regression. Realtime charts become more and more in demand.
    Suggestions by other people don’t quite work. The animation is weird. It’d be great if it was exactly like ot was before.
    I would not mind having to use extra methods if it’ll mean beautiful and meaningful animation.
    Are there any plans to improve this?

  5. I’m experimenting some changes in the dataset controller to get notified when data array(s) change and so cleanup meta data and get better animations when values are inserted or removed, and this without adding extra chart APIs. This allows many kind of animations, not only from right to left or left to right. I don’t know if it’s what you guys are looking for but I hope it should make real time charts experience better (see these examples: http://playground.abysscorp.org/chartjs/livecharts/).

Comments are closed.