chart.js load totally new data

前端 未结 20 1443
有刺的猬
有刺的猬 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:21

    I tried neaumusic solution, but later found out that the only problem with destroy is the scope.

    var chart;
    
    function renderGraph() {
        // Destroy old graph
        if (chart) {
            chart.destroy();
        }
    
        // Render chart
        chart = new Chart(
            document.getElementById(idChartMainWrapperCanvas),
            chartOptions
        );
    }
    

    Moving my chart variable outside the function scope, got it working for me.

提交回复
热议问题