Chart.js-RangeSlider icon indicating copy to clipboard operation
Chart.js-RangeSlider copied to clipboard

scope.chart.destroy is not a function

Open lapido opened this issue 8 years ago • 6 comments

Hi. In an attempt to update my chart, I'm getting this error that scope.chart.destroy is not a function. Thanks in advance for the help.

lapido avatar Oct 12 '16 19:10 lapido

Commit: 64fdaf4 should fix it, let me know if the issue is resolved, and I'll close it off. Sorry about the trouble!

schme16 avatar Oct 13 '16 00:10 schme16

Hi, I am trying to verify if the fix works form me:

After creating a new RangeSliderChart...

 window.myBar = new RangeSliderChart({
      chartData: barChartData, 
      chartOpts: chartOptions,  
      type: 'line',  
      chartCTX: ctx,  
      class: 'my-chart-ranger',  
      initial: [0, 143]  
    })  

Then I change my chartData and I execute the following line on my code:

window.myBar.update();

As a result the following error is shown on the console.

TypeError: window.myBar.update is not a function

I was able to fix this problem by adding the update function into the "RangeSliderChart" function inside "ranger" variable:

function RangeSliderChart (opts) {
    var ranger = {
        chartProto: new Chart(opts.chartCTX),
        datasets: opts.chartData,
        chartOpts: opts.chartOpts || {},
        options: opts,
        update: function() { this._draw(opts.chartCTX, ranger._getData( ranger.options.initial[0], ranger.options.initial[1] ), ranger.chartOpts, ranger.options) },
        sliderElement: $('<div>'),

Would you please advise if there is any other way of calling the update function without modifying your code?

Thanks in advance!

Franarroutado avatar Oct 16 '16 10:10 Franarroutado

Are you using ChartJS v1.x or v2.x, or using the 'all' bundle? These latest patches are to upgrade this the range slider lib to use v2.x, and which is not compatible with the v1.x branch...

If you are using the v1.x ChartJS, but aren't able to upgrade to the v2.x (for whatever reason), pull from this branch https://github.com/schme16/Chart.js-RangeSlider/tree/Chart.js-V1.x

schme16 avatar Oct 16 '16 13:10 schme16

Hi, Good point, I will review how I am using the chart.js-rangeslider.

My dependency versions are. chart.js": "^2.3.0" with chart.js-rangeslider 1.2.0.

Thank you very much.

Franarroutado avatar Oct 17 '16 05:10 Franarroutado

In anycase what you reported above is worth me looking into, I'll run a few tests on the change you mentioned and if it all checks out ok I'll push the update into the main branch

schme16 avatar Oct 18 '16 00:10 schme16

To destroy the Rangeslider rs I used the following code snippet.

var rs = new RangeSliderChart({...});
...
// to destroy rs
if (rs) {
   rs.chart.destroy();
   rs.sliderElement[0].parentNode.removeChild(rs.sliderElement[0]);
}

shourav9884 avatar Nov 29 '17 06:11 shourav9884