Highcharts未定义的值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Highcharts未定义的值相关的知识,希望对你有一定的参考价值。
$.getJSON("<?php echo $chartURL; ?>", function (data) {
var seriesData = [];
// split the data set into crypto and volume
for (i=0; i<data.length; i++) {
seriesData.push({
x: data[i].time,
y: data[i].open,
high: data[i].high
});
}
console.log(seriesData);
// Create the chart
Highcharts.stockChart('container', {
rangeSelector: {
selected: 0
},
title: {
text: 'AAPL Stock Price'
},
tooltip: {
formatter: function () {
return Highcharts.dateFormat('%d %b %Y', new Date(this.x)) + '<br/>' +
'Open: <b>' + this.y + '</b><br/>' +
'High: <b>' + this.point.high + '</b>';
}
},
series: [{
type: 'line',
name: 'USD',
data: seriesData,
turboThreshold: 0
}]
});
});
在for循环中我定义了值high
并且我在tooltip
中传递变量,但是脚本返回错误:
无法读取属性'high'的undefined
当我将tooltip
更改为:
tooltip: {
formatter: function() {
var s = '<b>'+ Highcharts.dateFormat('%d %b %Y', new Date(this.x)) +'</b>';
$.each(this.points, function(i, point) {
s += '<br/>High: ' + seriesData[i].high + '<br/>Price: ' + point.y;
});
return s;
},
shared: true
},
该脚本不会返回任何错误,但high
的值仍然相同,它不会更改。
我尝试使用:this.point.high, point.high, this.data.high, this.seriesData[i].high
...仍然我有错误undefined
所有值均取自JSON:
[{"time":1347321600000,"open":11.17,"high":11.35,"low":10.88,"close":11.33,"volumeto":721708.44},{"time":1347408000000,"open":11.33,"high":11.39,"low":10.78,"close":11.36,"volumeto":657004.1},{"time":1347494400000,"open":11.36,"high":11.4,"low":11.22,"close":11.4,"volumeto":233401.71},{"time":1347580800000,"open":11.4,"high":11.8,"low":11.32,"close":11.67,"volumeto":500768.38},{"time":1347667200000,"open":11.67,"high":11.79,"low":11.6,"close":11.75,"volumeto":190511.93},{"time":1347753600000,"open":11.75,"high":11.99,"low":11.72,"close":11.87,"volumeto":359833.88}...]
答案
high
键位于this.points[0].point
对象内,因此您的工具提示代码将为:
tooltip: {
formatter: function() {
console.log(this.points);
return Highcharts.dateFormat('%d %b %Y', new Date(this.x)) + '<br/>' +
'Open: <b>' + this.y + '</b><br/>' +
'High: <b>' + this.points[0].point.high + '</b>';
}
},
检查JSFIDDLE
以上是关于Highcharts未定义的值的主要内容,如果未能解决你的问题,请参考以下文章
Highcharts:无法使用AngularJS读取未定义的属性'parentGroup'
getSupportFragmentManager() 在活动扩展片段中未定义
具有Xpages / dojo的Highcharts 7.0.3