0

I am having an issue where I get the error in the title of this question when I create a chart like the one in this fiddle http://jsfiddle.net/w43m47hL/.

I get this problem when selecting a point.

this.select();

The problem occurs when performing these steps.

  1. create the chart
  2. click on a point to select it
  3. destroy the chart
  4. create the chart again

The size of the data set seems to have something to do with the problem. If you change 1500 to 15 you will see that you don't get this problem any more. However the data point that was selected is still selected after the chart is destroyed and created again. I would have thought that the point would not be selected since the chart was destroyed. How is the data point remembering that it was selected?

user1757006
  • 705
  • 2
  • 12
  • 23
  • You aren't destroying the original chart – charlietfl Jun 13 '16 at 17:52
  • I am destroying the chart as described in the documented fiddle here. http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/chart-destroy/. Can you tell me how I am doing it wrong? – user1757006 Jun 13 '16 at 18:58
  • 1
    It's not anything with highcharts but something with the way you create data. I updated the [fiddle](http://jsfiddle.net/w43m47hL/2/), the error does not occur anymore. – Rahul Sharma Jun 14 '16 at 09:52

1 Answers1

3

The issue is caused by keeping reference to "old" data array. During chart initialisation, you set the reference to data array, which is modified. So when you destroy chart, reference still exists. Use the copy of data ($.extend([],data)) in Highcharts objects.

  series: [{
    data: $.extend([], data)
  }],

Example:

Sebastian Bochan
  • 37,348
  • 3
  • 49
  • 75
  • I used this suggestion in addition to Rahul Sharma's comment to fix my problem. In production I just had to change (data: [ ]) to (data: data) and then set (var data = [ ]) before creating the chart. Works great now. – user1757006 Jun 14 '16 at 16:50