score:2

Accepted answer

OK, this error popped up again and that's because my comment above did not really solve it.

Here's the culprit: if you have a model that generates data for charts happen to return an empty array (say it's a new user and she hasn't added any data yet to the database), this empty array is passed to the controller -- which will then pass the empty array to the view with Highcharts.

When passing an empty array to my view containing Highcharts, Highcharts would run but would not find an element to inject the chart, because I also had a condition in the view that removed #container if there was no data.

Without where to put the chart, Highcharts returns an innerHTML error, that may or may not break your remaining javascript (my case).

The solution here had nothing to do with JS, but actually with putting a condition in my controller which would be in pseudo code:

if model that generates chart data returns empty array
    don't generate view containing Highcharts
else
    generate view containing Highcharts

Doing this not only I prevented the error for good but also reduced the overhead of running Highcharts when no data is present.

score:7

I had this problem. I had to surround the highChart creation code with document.ready

$(document).ready({
   chart = new Highcharts.Chart({ //my cool chart 
   });
});

score:8

For me the problem was that I wasn't including jQuery before including HighCharts.

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

Threw the errors:

Uncaught TypeError: Cannot read property 'addEvent' of undefined(anonymous function) @ highcharts.js:313(anonymous function) @ highcharts.js:315(anonymous function) @ highcharts.js:331

Uncaught TypeError: n.getOptions is not a function(anonymous function) @ highcharts-more.js:8(anonymous function) @ highcharts-more.js:55

Uncaught TypeError: Cannot read property 'fireEvent' of undefined(anonymous function) @ exporting.js:9(anonymous function) @ exporting.js:24

But if I included jQuery first it didn't.


Related Query

More Query from same tag