簡體   English   中英

Rails Chartkick:column_chart 中的日期格式

[英]Rails Chartkick: Date format in column_chart

我使用Chartkick Rails中,它看起來像column_chart日期格式比不同line_chart日期格式。 我已經檢查了我輸入的數據,並且圖表之間的數據是相同的。

折線圖有一個 x 軸(我想要的),看起來像: Nov 2016, Jan 2017, Mar 2017

柱狀圖: 2016-11-01, 2016-12-01, 2017-01-01...

<%= line_chart [
    {name: "Posts", data: @posts_over_time },
    {name: "Comments", data: @comments_over_time }
    ],
    xtitle: "Date",
    ytitle: "Engagement"
%>

<%= column_chart [
    {name: "Accepted", data: @number_charges_accepted },
    {name: "Declined", data: @number_charges_declined }
    ],
    stacked: true,
    xtitle: "Date",
    ytitle: "Transactions",
    # Additions I've tried:
    library: {
    format: 'MM/YY'
    },
    discrete: true
%>

根據這里的建議讓它工作: https : //github.com/ankane/chartkick/issues/352

@number_charges_declined = PastTransaction.where(project_id: @project.id).where(status: 'failed').group_by_month(:created_at, last: 6).count
@number_charges_accepted = PastTransaction.where(project_id: @project.id).where(status: 'successful').group_by_month(:created_at, last: 6).count
# Format dates for column_chart
@number_charges_declined = @number_charges_declined.transform_keys.with_index{ |key, i| if i % 2 == 0 then key.strftime("%b %Y") else " "*i end }
@number_charges_accepted = @number_charges_accepted.transform_keys.with_index{ |key, i| if i % 2 == 0 then key.strftime("%b %Y") else " "*i end }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM