gpt4 book ai didi

javascript - Highcharts 根据动态货币对绘制时间

转载 作者:行者123 更新时间:2023-11-28 04:19:33 24 4
gpt4 key购买 nike

我有一个 Highcharts ,显示当前时间兑欧元/美元货币对的情况。我每秒从货币层 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;
}())
}]
});
});

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

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

  1. 如何让 y 轴显示 0 到 4

  2. 如何让曲线下的区域具有像蓝色这样的颜色?

谢谢。

最佳答案

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

关于javascript - Highcharts 根据动态货币对绘制时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45545332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com