简体   繁体   English

在Highstock中在x轴上绘制数据

[英]Plotting data on x axis in Highstock

I am currently trying to plot some data which I receive via a HTTP request. 我目前正在尝试绘制通过HTTP请求接收到的一些数据。 The issue that I am having is that the x-axis doesn't plot the timestamp correctly because it it's in Unix format . 我遇到的问题是the x-axis doesn't plot the timestamp correctly because it it's in Unix format I've read some other similar question on SO such as: Example One 我已经阅读了其他类似的问题,例如: 示例一

The issue is that I'm not passing an object but directly an Unix time data . 问题是我没有传递对象,而是直接传递Unix time data When hovering the graph, you can see that the x-axis doesn't display the date and hour correctly. 将鼠标悬停在图表上时,您会看到x-axis未正确显示日期和小时。

Here is a fiddle with my current graph: Graph Fiddle 这是我当前图形的小提琴图形小提琴

Since you actually have datetime values, showing them using category is sort of a hack, and would also not show gaps between points correctly if they are not evenly spaced. 由于您实际上具有datetime值,因此使用category显示它们有点不妥,并且如果它们之间的间距不均匀,也不会正确显示点之间的间隙。

Instead you could merge your two arrays into pairs and then supply it to the series as proper XY values for a datetime axis. 相反,您可以将两个数组合并为对,然后将其作为datetime时间轴的适当XY值提供给该系列。 You also have to multiply your datetime values by 1000 to get milliseconds, which Highcharts expects. 您还必须将datetime值乘以1000才能获得Highcharts期望的毫秒数。

For example ( JSFiddle ), merging: 例如( JSFiddle ),合并:

dataArray.push(selectedData);
timeDataArray.push(selectedTime);

var mergedArray = timeDataArray.map(function(e, i) {
    return [e*1000, dataArray[i]];
});

And axis and series: 和轴及系列:

xAxis: {
    type: 'datetime'
},
series: [{
    name: 'AAPL',
    data: mergedArray
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM