score:0

with a couple of changes, your code should work

  1. looks like there is some problem with the chart.js version you are using. i changed it to the latest version (2.1 @ https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.1.0/chart.min.js)

  2. before you do $('#wheel').remove(); you need to do mychart.destroy(); to remove that particular chart from chart.js's internal list of objects (which it uses to resize existing charts when the window resizes)

  3. the following bit in your code clears off the complete data.

    ...
    for(i=chartdata.datasets[0].data.length-1; i>=0; i--) {
      chartdata.datasets[0].data.splice(i,1);
      chartdata.datasets[0].backgroundcolor.splice(i,1);
    }
    ...

since you then user chartdata to initialize your chart, you are effectively trying to draw a blank chart. i assume this was some sort of copy-paste error. i've changed it in the updated fiddle to just remove the last sector alone, like so.

var i=chartdata.datasets[0].data.length-1;
chartdata.datasets[0].data.splice(i,1);
chartdata.datasets[0].backgroundcolor.splice(i,1);

if you want all the sectors again for the next run, just remove that block.


fiddle - https://jsfiddle.net/wzbxuo5n/


Related Query

More Query from same tag