如何从ajax数据绘制高股票单线系列图
How to plot a highstock single line series graph from ajax data
我有一个rails应用程序,它从JSON API中获取英镑与肯尼亚先令的价值的货币信息数据。
我想用这些数据来绘制一段时间内英镑价值的时间序列图。
我使用AJAX填充数据到highcharts图表,我的代码如下:
<div id="currency", style="width: 220px, height:320px">
<script type="text/javascript">
$(document).ready(function(){
localhost = {}; //global namespace variable
localhost.currenctHTML = ""; //currency HTML built here
localhost.currencyValue = []; //array of percentage changes
localhost.currencyDate = []; //array of currency names
localhost.chart1 = {yAxisMin : null, yAxisMax : null};//obj holds things belonging to chart1
var url = '/forexes.json'
$.ajax({
url: url,
cache: false,
dataType: 'jsonp', //will set cache to false by default
context: localhost,
complete: function(data){
var a=JSON.parse(data.responseText);
// console.log(a);
var data_mapped = a.map(function (data){
return data.forex;
}).map(function (data) {
return {
currencyDate: data.published_at,
currencyValue: data.mean
}
});
this.currencyDate = _.pluck(data_mapped, 'currencyDate');
this.currencyValue = _.pluck(data_mapped, 'currencyValue');
console.log(this.currencyDate);
this.chart1.data.series[0].data = this.currencyValue;
this.chart1.data.xAxis.categories = this.currencyDate;
chart = new Highcharts.Chart(this.chart1.data);
}
});
localhost.chart1.data = { //js single-threaded, this obj created before callback function completed
chart: {
renderTo: "currency"
},
title: {
text: "Forex by Day"
},
xAxis: {
categories: null, //will be assigned array value during ajax callback
title: {
text: null
}
},
yAxis: {
title: {
text: "Pounds"
}
},
tooltip: {
formatter: function() {
return Highcharts.dateFormat("%B %e, %Y", this.x) + ': ' +
"$" + Highcharts.numberFormat(this.y, 2);
}
},
series: [{
name: 'Pound',
data: null
}
]
};
});
</script>
</div>
* * * *回报this.chart1.data.xAxis.categories = ["2003-01-01T00:00:00.000Z", "2003-01-02T00:00:00.000Z", "2003-01-03T00:00:00.000Z", "2003-01-04T00:00:00.000Z", "2003-01-05T00:00:00.000Z"]
this.chart1.data.series[0].data = [147.653, 148.007, 147.971, 148.202, 148.384, 147.888]
我如何使用这些数据来生成类似于下面的高点折线图
在hilitock中,您不能使用类别,只能使用日期时间类型,因此您应该将数据解析为时间戳并在数据中使用它
相关文章:
- 从桌面读取python文件时高亮显示代码
- 高亮显示时编辑文本大小和颜色
- 更改高贴图的缩放级别
- 如何从高股票图表中获取导航器选择
- 高股票图表中每个 yAxis 的 X 坐标
- 高股票图表在清除后不显示
- 高图表股票动画
- 三个.json文件'股票图表' - 高图表
- 高股票图表中的相对时间
- 将所有高股票报价中的日期更改为UNIX时间戳
- 启用滚动高图表,高股票
- 高股票比较股票如何定义数据
- 高股票没有正确渲染;在放大之前显示空序列
- 高股票与日期时间和多列
- 如何从ajax数据绘制高股票单线系列图
- 高股票与多个系列,工具提示跟随点,即使它被禁用
- 高股票-在同一页面上添加2个图表
- 在高股票图表的导航器中显示多个系列
- 带有多个烛台的图表.高股票/高图表
- 高股票:在烛台图表中添加系列