Highcharts未定义的值

问题描述 投票:0回答:1
$.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}...]
jquery highcharts tooltip
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.