[英]High charts plot time against a dynamic currency pair
I have a highchart chart that displays the current time against euro/dollar currency pair. 我有一个高图图表,显示了相对于欧元/美元货币对的当前时间。 I am getting live data from a currency layer per second api.
我正在从每秒API的货币层获取实时数据。
This is the chart http://jsfiddle.net/15vsdy63/25/ 这是图表http://jsfiddle.net/15vsdy63/25/
This is the javascript code 这是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;
}())
}]
});
});
I have theorized that in a worst case scenario, Euro/Dollar will never go past 4 usd for 1 euro, so in the Y-axis, i am thinking of having value 0 to 4 and x- axis will have the current time. 我已经得出理论,在最坏的情况下,欧元/美元永远不会超过1美元兑换4美元,因此在Y轴上,我正在考虑将值设置为0到4,x轴将具有当前时间。
In my example above, i cant display 0 to 4 in the y axis. 在上面的示例中,我无法在y轴上显示0到4。 Also i would love the area under the curve to have some color like blue.
我也希望曲线下的区域具有一些像蓝色的颜色。
How can i make the y -axis show 0 to 4 and 我怎样才能使y轴显示0到4并
How can i have area under the curve to have a color like blue? 我如何在曲线下留出面积以具有蓝色之类的颜色?
Thanks. 谢谢。
For the y-axis to show values between 0 & 4 use max: your value
and for the curve to have a color like blue just change the chart type to area chart:{type:area, ...
. 要使y轴显示0到4之间的值,请使用
max: your value
并且曲线要具有类似蓝色的颜色,只需将图表类型更改为面积chart:{type:area, ...
Here is your example: https://jsfiddle.net/68oe1oLf/ 这是您的示例: https : //jsfiddle.net/68oe1oLf/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.