【发布时间】:2018-03-04 11:52:36
【问题描述】:
$.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 中传递了变量,但脚本返回错误:
无法读取未定义的属性“高”
当我将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}...]
【问题讨论】:
-
point来自哪里? ->this.high -
@Andreas 我不知道这是否是你的意思,但所有值都取自 JSON,在变量
$chartURL中,我添加到我的帖子 JSON
标签: jquery highcharts tooltip