I am having a weird problem that I hope you can help me with.
I have Highcharts running on a dev website -- I use a simple form to allow the user to enter data.
On the same page, a Highchart shows once data is entered.
The data entry form has very simple jQuery-based snippets, eg. form validation, a counter for max number of characters, etc.
What happens is that when there is chart data in the database, the chart plots correctly, and the remaining JS snippets work as expected wen you try to enter new datapoints.
But if there is no data in the database (therefore no Highchart is shown), all my JS snippets stop working.
On Firebug console, I get this error when there is no data to form a chart:
jb is null
function n(m,h){kc=ya(a.title,m);tc=ya...play:""});Aa.body.appendChild(Qb)}Tc=
highcharts.js (line 47)
On Chrome, a different error shows as
Uncaught TypeError: Cannot set property 'innerHTML' of null
d.d.extend._Deferred.f.resolveWith jquery.min.js:16
d.d.extend.ready jquery.min.js:16
d.c.addEventListener.A
Again, these errors disappear as soon as I enter the first data point and a chart is formed.
Does anyone know what is happening and how I can get my JS to work when a Highchart is empty?
Any pointers are much appreciated. Thanks!
I am having a weird problem that I hope you can help me with.
I have Highcharts running on a dev website -- I use a simple form to allow the user to enter data.
On the same page, a Highchart shows once data is entered.
The data entry form has very simple jQuery-based snippets, eg. form validation, a counter for max number of characters, etc.
What happens is that when there is chart data in the database, the chart plots correctly, and the remaining JS snippets work as expected wen you try to enter new datapoints.
But if there is no data in the database (therefore no Highchart is shown), all my JS snippets stop working.
On Firebug console, I get this error when there is no data to form a chart:
jb is null
function n(m,h){kc=ya(a.title,m);tc=ya...play:""});Aa.body.appendChild(Qb)}Tc=
highcharts.js (line 47)
On Chrome, a different error shows as
Uncaught TypeError: Cannot set property 'innerHTML' of null
d.d.extend._Deferred.f.resolveWith jquery.min.js:16
d.d.extend.ready jquery.min.js:16
d.c.addEventListener.A
Again, these errors disappear as soon as I enter the first data point and a chart is formed.
Does anyone know what is happening and how I can get my JS to work when a Highchart is empty?
Any pointers are much appreciated. Thanks!
Share Improve this question asked Mar 30, 2011 at 0:32 pepepepe 9,90925 gold badges117 silver badges192 bronze badges 6 | Show 1 more comment3 Answers
Reset to default 8For 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.
I had this problem. I had to surround the highChart creation code with document.ready
$(document).ready({
chart = new Highcharts.Chart({ //my cool chart
});
});
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.
if(WeHaveData){drawChart(WeHaveData);}
– Mark Coleman Commented Mar 30, 2011 at 0:44null
or something else maybe highchart is not behaving correctly. If you could give a sample of how the js looks with data present with and without might be able to help more. If a jsfiddle.net could be made even better – Mark Coleman Commented Mar 30, 2011 at 0:52