highstock 2.0.4不适用于IE和Firefox

时间:2014-12-09 11:29:41

标签: javascript highcharts cross-browser highstock

我的数据如下:

{"01.12.10 00:00":-1.5821800231934,"01.12.10 00:05":-1.5570800304413,"01.12.10 00:10":-1.5885699987411,"01.12.10 00:15":-1.6257599592209,"01.12.10 00:20":-1.6307400465012,"01.12.10 00:25":-1.6432000398636,"01.12.10 00:30":-1.655179977417,"01.12.10 00:35":-1.646919965744,"01.12.10 00:40":-1.6347700357437,"01.12.10 00:45":-1.6490000486374,"01.12.10 00:50":-1.6404999494553,"01.12.10 00:55":-1.6160600185394,"01.12.10 01:00":-1.6089400053024,"01.12.10 01:05":-1.6082600355148,"01.12.10 01:10":-1.6159199476242,"01.12.10 01:15":-1.5781999826431,"01.12.10 01:20":-1.6013100147247,"01.12.10 01:25":-1.636440038681,"01.12.10 01:30":-1.6679799556732,"01.12.10 01:35":-1.6709300279617,"01.12.10 01:40":-1.7158499956131,"01.12.10 01:45":-1.7515499591827,"01.12.10 01:50":-1.7836400270462,"01.12.10 01:55":-1.7883299589157,"01.12.10 02:00":-1.8029299974442,"01.12.10 02:05":-1.8306200504303,"01.12.10 02:10":-1.8690099716187,"01.12.10 02:15":-1.8802800178528,"01.12.10 02:20":-1.890319943428,"01.12.10 02:25":-1.9045300483704,"01.12.10 02:30":-1.9173899888992,"01.12.10 02:35":-1.9262299537659,"01.12.10 02:40":-1.9494600296021,"01.12.10 02:45":-1.9754300117493,"01.12.10 02:50":-2.0177900791168,"01.12.10 02:55":-2.1353900432587,"01.12.10 03:00":-2.2930901050568,"01.12.10 03:05":-2.4463000297546,"01.12.10 03:10":-2.4375700950623,"01.12.10 03:15":-2.4210600852966,"01.12.10 03:20":-2.4662098884583}

我初始化图表的脚本如下:

getGraphData: function(params){         
    var self = this;
    $.ajax({
        url: '_someUrl' + params,
        type: 'GET',
        success:function(result){                   
            self.renderBarChart(self.formatData(result));
        },
        error: function(req, status, error){
            console.log(error);
        }
    });
},

formatData: function(rawData){

    var self = this;
    var result = $.parseJSON(rawData);
    var formattedData = _.map(result, function(value, date){                            
        var formattedDate =self.formatDate(date);
        return [formattedDate, value];;
    }); 

    return formattedData;
},

formatDate: function(rawDate){

    var dateTimeArray = rawDate.split(' ');

    var dateArray =  dateTimeArray[0].split('.'); 

    var newDateTimeString = (dateArray[1] + '.' + dateArray[0] + '.' + dateArray[2] + ' ' + dateTimeArray[1]);

    return new Date(newDateTimeString).getTime();
},

renderBarChart: function(data){ 
    Highcharts.setOptions({
        lang: {
            rangeSelectorFrom: 'Von',
            rangeSelectorTo: 'Bis'
        }                   
    });

    $('#container').highcharts('StockChart', {
        chart: {
                alignTicks: false,
                type: 'column'
        },
        xAxis: {
            type: 'datetime',
            title: {
                text: 'Date'
            },
            labels: {
                formatter: function() {                         
                    return Highcharts.dateFormat(" %e %b %Y %H:%M:%S", this.value);
                },
                rotation: 90
            },
            tickLength: 0
        },
        rangeSelector: {                        
            selected: 1,
            allButtonsEnabled: true,                        
            enabled: true
        },
        series: [{
            name: 'Datai',
            data:data,
            tooltip: {
                formatter: function() { 
                    var tooltip = '<b>Datum</b>: ' + Highcharts.dateFormat("%e %b %Y %H:%M:%S", this.x) + '</b><br>';
                    tooltip += '<b>Werte: </b>' + this.y;
                    return tooltip;                     
                }
            }
        }]
    }, function(chart) {                   
        setTimeout(function() {
            $('input.highcharts-range-selector', $('#' + chart.options.chart.renderTo)).datepicker()
        }, 0)
    });     
}   

它适用于chrome,但在任何版本的IE和Firefox上都显示以下错误。

TypeError: segmentPositions is undefined highstock.src.js:17778
TypeError: series[j].tooltipPoints is undefined highstock.src.js:9113

我认为问题在于数据分组,但由于我不需要对数据进行分组,因此我尝试了各种选项,但无法使其正常工作。任何帮助你都会受到极大的关注。

1 个答案:

答案 0 :(得分:0)

您的json不正确,该点应该有x / y字段,x应该是时间戳(以毫秒为单位的时间),而不是像你一样。