Highstock with data.csv从01.01.1970开始 [英] Highstock with data.csv starts with 01.01.1970

查看:222
本文介绍了Highstock with data.csv从01.01.1970开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始尝试使用Highstock图表来显示我的光伏数据。
问题是,图表从01-01-1970 00:00:00开始。
它忽略我的csv文件中的日期和时间。



此代码与这里的一些示例相同,但不起作用。 p>

我的data.csv


2011-08-01 00:00:00,155 < br>
2011-08-02 00:00:00,156

2011-08-03 00:00:00,157

2011-08-03 00:06:00,160

2011-08-04 00:00:00,120


我的index.html

  $(document).ready(function(){

var c = [];
var d = [];
var options = {
chart:{
renderTo:'content',
defaultSeriesType:'line'
},

xAxis:{
title:{
text:'Datum'
},
type:'datetime',
categories:c
},
yAxis:{
title:{
text:'Stromertrag [wH]'
}
},
系列:[{
data:d,
}]
};

var jqxhr = $ .get('../ data / data.csv',function(data){
var lines = data.split('\\\
');
$ .each(lines,function(lineNo,line){
var items = line.split(',');
c.push(items [0]);
d.push(parseInt(items [1]));
})
var chart = new Highcharts.StockChart(options);

});
});

解决方案>

Highcharts使用时间戳(以毫秒为单位的时间),因此您可以使用pointStart / pointInterval或将毫秒设置为JSON中的x值,或使用Date.UTC()函数返回正确的数据。



数据应按x升序排序


I've started experimenting with Highstock charts to visualize my photovoltaics data. The problem is, that the chart starts with 01-01-1970 00:00:00. It ignores the date and time in my csv-file.

This code is the same as some examples here, but it doesn't work.

My data.csv

2011-08-01 00:00:00,155
2011-08-02 00:00:00,156
2011-08-03 00:00:00,157
2011-08-03 00:06:00,160
2011-08-04 00:00:00,120

My index.html

$(document).ready(function() {

    var c = [];
    var d = [];
    var options = {
            chart: {
                renderTo: 'content',
                defaultSeriesType: 'line'
            },

            xAxis: {
                title: {
                    text: 'Datum'
                },
                type: 'datetime',
                categories: c
            },
            yAxis: {
                title: {
                    text: 'Stromertrag [wH]'
                }
            },
            series: [{
                data: d,
            }]
    };

    var jqxhr = $.get('../data/data.csv', function(data) {
        var lines = data.split('\n');
        $.each(lines, function(lineNo, line) {
            var items = line.split(',');
            c.push(items[0]);
            d.push(parseInt(items[1]));
        })
        var chart = new Highcharts.StockChart(options);

    });
});

解决方案

Highcharts use timestamps (time in miliseconds), so you can use pointStart/pointInterval or setting miliseconds as x values in your JSON or use Date.UTC() function to return correct data.

Data should be sorted by x ascending

这篇关于Highstock with data.csv从01.01.1970开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆