chart.js load totally new data

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

    I had huge problems with this

    First I tried .clear() then I tried .destroy() and I tried setting my chart reference to null

    What finally fixed the issue for me: deleting the element and then reappending a new to the parent container


    There's a million ways to do this:

    var resetCanvas = function () {
      $('#results-graph').remove(); // this is my  element
      $('#graph-container').append('');
      canvas = document.querySelector('#results-graph'); // why use jQuery?
      ctx = canvas.getContext('2d');
      ctx.canvas.width = $('#graph').width(); // resize to parent width
      ctx.canvas.height = $('#graph').height(); // resize to parent height
    
      var x = canvas.width/2;
      var y = canvas.height/2;
      ctx.font = '10pt Verdana';
      ctx.textAlign = 'center';
      ctx.fillText('This text is centered on the canvas', x, y);
    };
    

提交回复
热议问题