Highcharts,堆叠列范围,y轴为日期

时间:2015-06-10 07:58:41

标签: javascript highcharts highstock

当系列数据被硬编码时,highcharts正在渲染图表,当数据从后端传递给变量时,它不会生成图表。

series: [{
                name: 'T1',
                stack: 'Tasks',
                color: 'blue',
                data: [ { x: 0,
                       low: Date.UTC(2015, 2, 13, 11, 42, 02),
                       high: Date.UTC(2015, 2, 13, 14, 15, 53)},
                     { x: 1,
                       low: Date.UTC(2015, 2, 13, 11, 42, 02),
                       high: Date.UTC(2015, 2, 13, 11, 42, 02)},
                     { x: 2,
                       low: Date.UTC(2015, 2, 13, 11, 42, 02),
                       high: Date.UTC(2015, 2, 13, 15, 54, 23)},
                     { x: 3,
                       low: Date.UTC(2015, 2, 13, 11, 42, 02),
                       high: Date.UTC(2015, 2, 13, 14, 17, 08)},
                     { x: 4,
                       low: Date.UTC(2015, 2, 13, 11, 42, 02),
                       high: Date.UTC(2015, 2, 13, 17, 23, 13)} ]
            }, {
                name: 'T2',
                stack: 'Tasks',
                color: 'green',
                data: [ { x: 0,
                   low: Date.UTC(2015, 2, 13, 14, 15, 53),
                   high: Date.UTC(2015, 2, 13, 14, 17, 08)},
                 { x: 1,
                   low: Date.UTC(2015, 2, 13, 11, 42, 02),
                   high: Date.UTC(2015, 2, 13, 13, 23, 02)},
                 { x: 3,
                   low: Date.UTC(2015, 2, 13, 14, 17, 08),
                   high: Date.UTC(2015, 2, 13, 14, 24, 55)} ]
            }, {
                name: 'T3',
                stack: 'Tasks',
                color: 'red',
                data: []
            }]

当值来自后端时,代码为

series: [{
                name: 'T1',
                stack: 'Tasks',
                color: 'blue',
                data: (function(){
                    var data = [];
                    var temp = {};
                    for(i in msg.T1){
                        temp.x = msg.T1[i].x;
                        // temp.low = new Date(msg.T1[i].low) or Date.UTC(new Date(msg.T1[i].low);
                        // temp.high = new Date(msg.T1[i].high);
                        temp.low = parseInt(i);
                        temp.high = parseInt(i)+2;
                        data.push(temp);
                    }
                    return data;
                }())
            }, {
                name: 'T2',
                stack: 'Tasks',
                color: 'green',
                data: (function(){
                    var data = [];
                    var temp = {};
                    for(i in msg.T2){
                        temp.x = msg.T2[i].x;
                        // temp.low = new Date(msg.T2[i].low);
                        // temp.high = new Date(msg.T2[i].high);
                          temp.low = parseInt(i);
                        temp.high = parseInt(i)+2;
                        data.push(temp);
                    }
                    return data;
                }())
            }, {
                name: 'T3',
                stack: 'Tasks',
                color: 'red',
                data: (function(){
                    var data = [];
                    var temp = {};
                    for(i in msg.T3){
                        temp.x = msg.T3[i].x;
                        // temp.low = new Date(msg.T3[i].low);
                        // temp.high = new Date(msg.T3[i].high);
                          temp.low = parseInt(i);
                        temp.high = parseInt(i)+2;
                        data.push(temp);
                    }
                    return data;
                }())
            }]
        });

第二个代码,尽管没有错误,但不会渲染图表。 数据格式有什么问题

1 个答案:

答案 0 :(得分:0)

问题是解决的,问题是temp.x中的x值,传递给系列的数据对象,应该只是整数,不允许使用字符串或任何其他数据类型。修复修复图表