chart.js load totally new data

前端 未结 20 1375
有刺的猬
有刺的猬 2020-11-28 21:12

The API for chart.js allows one to edit points of the datasets loaded into it, for example:

.update( )

Calling update() on

20条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 21:29

    I ran into the same issue, I have 6 pie charts on a page which can all be updated at the same time. I am using the following function to reset chart data.

    // sets chart segment data for previously rendered charts
    function _resetChartData(chart, new_segments) {
        // remove all the segments
        while (chart.segments.length) {
            chart.removeData();
        };
    
        // add the new data fresh
        new_segments.forEach (function (segment, index) {
            chart.addData(segment, index);
        });
    };
    
    // when I want to reset my data I call
    _resetChartData(some_chart, new_data_segments);
    some_chart.update();

提交回复
热议问题