Chart.js: Dynamic Changing of Chart Type (Line to Bar as Example)

后端 未结 3 1436
独厮守ぢ
独厮守ぢ 2020-12-17 19:53

I am trying to hot swap chart types based on select box changes. If data needs to be updated, it changes.

So for example, on page load I create a chart like this:

3条回答
  •  既然无缘
    2020-12-17 20:17

    Just to follow up that this is now fixed in v.2.1.3, as followed through by https://stackoverflow.com/users/239375/nathan

    document.getElementById('changeToLine').onclick = function() {
      myChart.destroy();
      myChart = new Chart(ctx, {
        type: 'line',
        data: chartData
      });
    };
    

    Confirmed fixed in latest version. Check out http://codepen.io/anon/pen/ezJGPB and press the button under the chart to change it from a bar to a line chart.

提交回复
热议问题