[英]How to achieve Time series, zoomable highcharts on ruby
I'd like to achieve time series, zoomable highcharts,like following picture, on ruby. 我想在红宝石上实现时间序列,可缩放的高位图表,如下图所示。 http://www.highcharts.com/demo/line-time-series http://www.highcharts.com/demo/line-time-series
I've achieved the following line chart using lazy_high_charts However I have no idea how to get the time series chart. 我已经使用lazy_high_charts实现了以下折线图。但是,我不知道如何获取时间序列图。 Could you tell me how to solve the problem? 你能告诉我如何解决这个问题吗?
def show
@graph = LazyHighCharts::HighChart.new('graph') do |f|
f.title(text: 'A/B Price')
f.xAxis(categories: @date_array)
f.plotOptions(line: {marker: {enabled: false}})
f.series(name: 'A/B', data: @rate_array)
end
end
You need to add some area
attributes to your plotOptions
. 您需要向plotOptions
添加一些area
属性。 A very simple example would be: 一个非常简单的示例是:
f.plotOptions(line:{marker: {enabled: false}}, area: {fillColor: '#000000'})
A more complex example is link on http://www.highcharts.com/demo/line-time-series : 一个更复杂的示例是http://www.highcharts.com/demo/line-time-series上的链接:
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
By writing as following, I've got the chart like attached picture. 通过如下编写,我得到了如下图所示的图表。
@graph = LazyHighCharts::HighChart.new('graph') do |f|
f.title(text: 'A/B')
f.xAxis(categories: @date_array)
f.yAxis(title: {text: 'Exchange rate'})
f.chart(
type: "area",
zoomType: 'x'
)
f.plotOptions(
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, "rgb(255, 255, 255)"],
[1, "rgb(240, 240, 255)"]
]
},
marker: {
radius: 1
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: nil
}
)
f.series(name: 'A/B', data: @rate_array)
Two things: 两件事情:
1) f.xAxis(categories: @date_array)
- creates an array of categories, while you need f.xAxis(:type=> "datetime")
instead. 1) f.xAxis(categories: @date_array)
-创建一个类别数组,而您需要f.xAxis(:type=> "datetime")
。 Also, @rate_array
should be an array of arrays, like this: 同样, @rate_array
应该是一个数组数组,如下所示:
[ [date_1, value_1], [date_2, value_2], ... ]
2) Change type from line
to area
, for example: 2)将类型从line
更改为area
,例如:
f.series(:type=> "area", :name=> 'A/B', :data=> @rate_array)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.