schme16 / Chart.js-RangeSlider

This adds the option of having a range slider to your Chart.JS Charts, to allow you to select a specific data scale
MIT License
33 stars 11 forks source link

scope.chart.destroy is not a function #2

Open lapido opened 8 years ago

lapido commented 8 years ago

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.

schme16 commented 8 years ago

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

Franarroutado commented 8 years ago

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!

schme16 commented 8 years ago

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

Franarroutado commented 8 years ago

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.

schme16 commented 8 years ago

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

shourav9884 commented 6 years ago

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]);
}