在缩放柱形图后,Highstock返回不正确的x值(日期时间)

时间:2013-02-13 14:47:49

标签: highstock

在任何类型的缩放(鼠标拖动,范围选择器,日期输入)之后,点击事件返回的日期时间通常是不正确的。我使用面积图时还没有发现这个问题,使用条形图和柱形图都找到了它 要重新创建:运行小提琴,使用鼠标在几个列上进行缩放,单击数据点。警报将显示返回的日期时间。请注意它与工具提示(正确)不同。
通常在第一次单击后失败,即使对于相同的数据点也是如此。
BTW useUTC设置无关紧要。

小提琴:http://jsfiddle.net/jrEDT/

完整性代码:

$(function() {
var seriesOptions = [],
    yAxisOptions = [],
    seriesCounter = 0,
    names = ['MSFT'],
    colors = Highcharts.getOptions().colors;

$.each(names, function(i, name) {

    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?',   function(data) {

        seriesOptions[i] = {
            name: name,
            data: data,
            type: 'column'
        };

        // As we're loading the data asynchronously, we don't know what order it will arrive. So
        // we keep a counter and create the chart when all the data is loaded.
        seriesCounter++;

        if (seriesCounter == names.length) {
            createChart();
        }
    });
});

// create the chart when all data is loaded
function createChart() {
    Highcharts.setOptions({
        global: {
            useUTC: false // datetime reflects time on db (ie, local) rather than GMT
        }
    });
    chart = new Highcharts.StockChart({
        chart: {
            renderTo: 'container',
            zoomType: 'x'
        },
        exporting: {
            enabled: false
        },
        rangeSelector: {
            selected: 4
        },
        yAxis: {
            plotLines: [{
                value: 0,
                width: 2,
                color: 'silver'
            }],
            offset: 25
        },
        plotOptions: {
            series: {
                cursor: 'pointer',
                allowPointSelect: true,
                point: {
                    events: {
                        click: function() {
                            var series = this.series.name;
                            var utc = this.x;
                            var d = Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x);
                           alert(d);
                        }
                    }
                }
            }
        },
        tooltip: {
            formatter:function(a,b,c){
                var d = Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x);
                return d;
            },
            enable:true
        },
        series: seriesOptions
    });
}

});

谢谢!

1 个答案:

答案 0 :(得分:0)