如何为Highchart创建数组? [英] How to create arrays for Highchart?
问题描述
这是我的一些Highchart JavaScript代码
:
系列:[
{
name:Indtjening,
pointInterval:<%= 1.day * 1000%> ;,
pointStart:<%= 1.day。 before.to_i * 1000%>,
data:<%= Reklamer.sum(:earn,:order =>:dato,:group => dato).values%>
},
{
名称:Iqmedier,
颜色:'#DBD200',
pointInterval:<%= 1.day * 1000%> ,
pointStart:<%= 1.day.ago.to_i * 1000%> ;,
data:<%= Reklamer.where(:virksomhed =>'Iqmedier')。地图(&:赚取)%>
}
,
{
名称:Euroads,
颜色:'#1B7B94',
pointInterval:<%= 1.day。 to_i * 1000%> ;,
pointStart:<%= 1.day.ago.to_i * 1000%> ;,
data:<%= Reklamer.where(:virksomhed =>' Euroads')。all.map(&:earn)%>
$]
我的表格:
id virksomhed dato赚
10 Iqmedier 2011-02-15 00:00:00 0
11 Euroads 2011-02-01 00:07:24 144
15 Iqmedier 2011-02-15 00:00:00 5
我的图表 - as你可以看到Iqmedier有错误的日期(二月十七日),所有其他的酒吧也有错误的日期。
![我的图表] [1]
http://i.stack .imgur.com / E1MIN.png
Indtjening应取Iqmedier和Euroads的总和,并从列数据的最后一个日期开始。
如何在dato中找到最后一个日期并将其创建为一个整数?
要将这些日期转换为HighCharts,您必须这样做:
dato.utc.to_i * 1000
这应该可以解决您的问题。
请注意,你必须乘以(* 1000)才能得到毫秒格式。
I am trying to create some arrays for high charts. I have watched the is railcasts episode about how to create a highchart. http://railscasts.com/episodes/223-charts
Here is my some of my Highchart JavaScript code :
series: [
{
name: "Indtjening",
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 1.day.ago.to_i * 1000%>,
data: <%= Reklamer.sum(:earn, :order => :dato , :group => :dato).values %>
},
{
name: "Iqmedier",
color: '#DBD200',
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 1.day.ago.to_i * 1000 %>,
data: <%= Reklamer.where(:virksomhed => 'Iqmedier').all.map(&:earn) %>
}
,
{
name: "Euroads",
color: '#1B7B94',
pointInterval: <%= 1.day.to_i * 1000 %>,
pointStart: <%= 1.day.ago.to_i * 1000 %>,
data: <%= Reklamer.where(:virksomhed => 'Euroads').all.map(&:earn) %>
}]
My table:
id virksomhed dato earn
10 Iqmedier 2011-02-15 00:00:00 0
11 Euroads 2011-02-01 00:07:24 144
15 Iqmedier 2011-02-15 00:00:00 5
My chart - as you can see Iqmedier has the wrong date (17. February) and all the other bars do also have the wrong date. ![My chart][1] http://i.stack.imgur.com/E1MIN.png
Indtjening should take the sum of Iqmedier and Euroads and start from the last date in the column dato.
How do find the last date in the dato and create it to an integer?
To convert these date to HighCharts you have to do this:
dato.utc.to_i*1000
This should resolve your problem with datas.
Note that you have to multiply (* 1000) to get the milliseconds "format".
这篇关于如何为Highchart创建数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!