2012-08-09 200 views
0

我正在製作一個應用程序,有很多問題後,我最終做出了陰謀,但現在需要正確的數據,但我需要做一些調整。高人問題:問題

例如,如果一個用戶註冊在同一天一個新的日誌應採取日誌的成本,並把它添加到當天的日誌或簡單地表明,如果沒有更多的,我按照railcast episode 223和helpme一點。但我的問題是:當我添加一個新的日誌,它創建一個新的酒吧: (只有2個日誌,我要創建一個新的日誌) enter image description here 這裏是我的應用程序做的。 enter image description here

我也需要修復的日期時間,這裏是我的代碼:

$(function() { 
     new Highcharts.Chart({ 
     chart: { renderTo: 'foo_chart',defaultSeriesType: 'column' }, 
     title: { text: 'tanking costs daily' }, 
     xAxis: { type: 'datetime' }, 
     yAxis: { 
      title: { text: 'cost' } 
     }, 
     tooltip: { 
      formatter: function() { 
      return Highcharts.dateFormat("%B %e %Y", this.x) + ': ' + '$' + Highcharts.numberFormat(this.y, 2); 
      } 
     }, 
     series: [{ 
      name: 'Days', 
      pointInterval: <%= 1.day * 1000 %>, 
      pointStart: <%= 1.weeks.ago.at_midnight.to_i * 1000 %>, 
      data:[ 
      <% for tankinglog in @tankinglog %> 
       <%= "(" + tankinglog.cost.to_f.round(2).to_s + "),"%> 
      <% end %> 
      ] 
     }] 
     }); 
    }); 

如果你看到圖片上的名單上有3個數量級......最後2個日誌具有相同的日期,這些必須出現在與他們的費用總和相同的酒吧

+0

您是如何獲取數據的?你的系列是什麼樣的?您是否只想顯示第一天所做的所有日誌,或者是否想要顯示第一天每個日誌創建的時間? – wergeld 2012-08-09 19:11:08

回答

1

你的問題很混亂。你想把所有的數據彙總到一個欄中?爲data列表中的每個號碼創建一個新欄。因此,您的for-each循環爲@tankinglog中的每個項目創建一個新欄。解決方案是將所需要的數據加到一個數字中,然後將其添加到列表中。

我不確定你在問什麼,因爲你的問題很差,但這裏所有的值都歸入一個欄中。

$(function() { 
    new Highcharts.Chart({ 
    chart: { renderTo: 'foo_chart',defaultSeriesType: 'column' }, 
    title: { text: 'tanking costs daily' }, 
    xAxis: { type: 'datetime' }, 
    yAxis: { 
     title: { text: 'cost' } 
    }, 
    tooltip: { 
     formatter: function() { 
     return Highcharts.dateFormat("%B %e %Y", this.x) + ': ' + '$' + Highcharts.numberFormat(this.y, 2); 
     } 
    }, 
    series: [{ 
     name: 'Days', 
     pointInterval: <%= 1.day * 1000 %>, 
     pointStart: <%= 1.weeks.ago.at_midnight.to_i * 1000 %>, 
     data:[ 
     <% 
     result = 0; 
     for tankinglog in @tankinglog 
      result += tankinglog.cost.to_f 
     end %> 
     <%= result.round(2).to_s %> 
     ] 
    }] 
    }); 
}); 
+0

對不起,這個問題很困惑 這是如此接近,我需要, – Asantoya17 2012-08-09 19:23:59

+0

我需要的是如果有一天變得更多的日誌。加入這些日誌並顯示在一個單一的酒吧,所以,顯示各種酒吧的日​​志總成本...再次對不起,我不會說英語這麼多 – Asantoya17 2012-08-09 19:29:05

+0

如果你看到圖片上的列表我有3個日誌...最後2個日誌有相同的日期,這些日誌必須出現在同一個欄中,其費用總計爲 – Asantoya17 2012-08-09 19:31:41