I am trying to create a highstock chart, but am getting the following error:
error: Uncaught TypeError: w[(intermediate value)(intermediate value)(intermediate value)] is not a constructor
My JSON seems valid, and my javascript too, any idea howto fix this?
Javascript:
$.getJSON('<?php echo SITE_URL; ?>analytic/weekly_views_json', function(data)
{
// Create the chart
$('#container2').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
name: 'AAPL Stock Price',
data: data,
type: 'spline',
}]
});
});
Json:
[[1420547368,1],[1423225768,1],[1425644968,1],[1428319768,1],[1430911768,1],[1433590168,1],[1452083368,1],[1454761768,1],[1457267368,1],[1458131368,1],[1459942168,1],[1494070168,1]]
I am trying to create a highstock chart, but am getting the following error:
error: Uncaught TypeError: w[(intermediate value)(intermediate value)(intermediate value)] is not a constructor
My JSON seems valid, and my javascript too, any idea howto fix this?
Javascript:
$.getJSON('<?php echo SITE_URL; ?>analytic/weekly_views_json', function(data)
{
// Create the chart
$('#container2').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
name: 'AAPL Stock Price',
data: data,
type: 'spline',
}]
});
});
Json:
[[1420547368,1],[1423225768,1],[1425644968,1],[1428319768,1],[1430911768,1],[1433590168,1],[1452083368,1],[1454761768,1],[1457267368,1],[1458131368,1],[1459942168,1],[1494070168,1]]
Share
Improve this question
asked Apr 26, 2016 at 10:22
user4655002user4655002
4
- 2 The timestamps look like a UNIX format, but should be multiplied by 1000 to achieve JS format. Have you a live demo of your chart, because your code is correct. – Sebastian Bochan Commented Apr 26, 2016 at 11:06
- The code you have provided seems to work jsfiddle/o079d5s6/2 Could you create a fiddle demonstrating the issue? – Yury Tarabanko Commented Jul 24, 2016 at 7:26
- @YuryTarabanko I exactly use highchart example but I have got above error! jsfiddle highchart example – MHS Commented Jul 24, 2016 at 7:38
- @randommman Could you find the solution? – MHS Commented Jul 24, 2016 at 7:49
2 Answers
Reset to default 6First solution:
I had same error, i used highchart
as below in my HTML
code:
<head>
<script src="https://code.highcharts./highcharts.js"></script>
...
</head>
and my js
code was:
$('#container').highcharts('StockChart', {
...
});
with respect to highchart documention
, we must use Highcharts.Chart
to create new highstock
.
so i changed my code to:
<head>
<script src="https://code.highcharts./highcharts.js"></script>
...
</head>
and my js
code was:
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
...
});
and this error has been resolved!
Second solution:
also with respect to this documentation, if you are running Chart and StockChart in bination, you only need to load the highstock.js file.
so changed my code to:
<head>
<script src="https://code.highcharts./stock/highstock.js"></script>
...
</head>
and my js
code was:
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
...
});
This worked for me
<script src="../lib/highcharts.js"/>
<script src="../lib/highcharts-more.js"/>
var chart = new Highcharts.Chart({
chart: {
renderTo: 'Temperature'
},
title: {
text: 'HighStock'
},
legend: {
enabled: true
},
xAxis: {
categories: ['1','2','3','4'],
title: {
text: 'day'
}
},
yAxis: {
title: {
text: 'values'
}
},
series: [{
name: 'temperature',
data: [
[5,30],[10,35],[15,40],[20,45]
],
}]
});