高图表绘制时间与动态货币对



我有一个高图表,显示当前对欧元/美元货币对的时间。我正在从每秒货币层 API 获取实时数据。

这是图表 http://jsfiddle.net/15vsdy63/25/

这是JavaScript代码

$(document).ready(function () {
window.setInterval(function(){
$.get( "http://firmbridgecapital.com/live.php", function( data ) {
localStorage.setItem("data", data);
});
}, 5000);
Highcharts.setOptions({
global: {
useUTC: false
}
});
Highcharts.chart('container', {
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 5000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -150; i <= 0; i += 25) {
data.push({
x: time,
y: parseInt(localStorage.getItem("data"))
});
}
return data;
}())
}]
});
});

我的理论是,在最坏的情况下,欧元/美元永远不会超过 4 美元兑换 1 欧元,因此在 Y 轴上,我正在考虑将值 0 到 4 并且 x 轴将具有当前时间。

在上面的示例中,我无法在 y 轴上显示 0 到 4。我也希望曲线下的区域有一些颜色,如蓝色。

  1. 如何使 y 轴显示 0 到 4 和

  2. 我怎样才能在曲线下有面积来获得蓝色这样的颜色?

谢谢。

要使 y 轴显示 0 和 4 之间的值,请使用max: your value并且对于曲线具有蓝色等颜色,只需将图表类型更改为面积chart:{type:area, ...即可。下面是您的示例:https://jsfiddle.net/68oe1oLf/

最新更新