When I input the data directly in high charts, it works perfectly:
$(function () {
$('#container').highcharts({
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: [0.818883519277839, 0.8118310020160356, 0.8292750491048191, 0.8207364844853503, 0.8187873450691459, 0.8098962769401326, 0.8060550491107373,
0.7960675107192992, 0.7798022181293245, 0.7747131667969733, 0.77704753581292, 0.780881503288139, 0.7808802272036436, 0.7828232760186384,
0.7745154579263632, 0.7858447215087305, 0.7903196602781966, 0.7904203695573747, 0.7842096993261638, 0.7736738976551895]
}]
});
});
But if I try to use a for-loop to go through my array and replace it as the data source, it doesn't work. Is there a proper way to do this?
For example:
myArray = [0.818883519277839, 0.8118310020160356, 0.8292750491048191, 0.8207364844853503, 0.8187873450691459, 0.8098962769401326, 0.8060550491107373,
0.7960675107192992, 0.7798022181293245, 0.7747131667969733, 0.77704753581292, 0.780881503288139, 0.7808802272036436, 0.7828232760186384,
0.7745154579263632, 0.7858447215087305, 0.7903196602781966, 0.7904203695573747, 0.7842096993261638, 0.7736738976551895]
and then
series: [{
name: 'Tokyo',
data: myArray,
}]
Thank you!