开发者

How to create arrays for Highchart?

开发者 https://www.devze.com 2023-02-10 21:56 出处:网络
I am trying to create some arrays for 开发者_如何学Gohigh charts. I have watched the is railcasts episode about how to create a highchart. http://railscasts.com/episodes/223-charts

I am trying to create some arrays for 开发者_如何学Gohigh 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".

0

精彩评论

暂无评论...
验证码 换一张
取 消