How to create arrays for Highchart?

自作多情 提交于 2019-12-24 10:48:32

问题


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?


回答1:


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".



来源:https://stackoverflow.com/questions/5031253/how-to-create-arrays-for-highchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!