Rails chartkick stacked bar charts

我的未来我决定 提交于 2019-11-29 11:57:20

问题


I'm trying to create a stacked bar chart using Rails Chartkick gem and I'm using Google charts API.

I have use this line to generate the bar chart using chartkick.

<%= bar_chart data, :library => {:isStacked => true} %> 

But what i'm getting is a simple bar chart not a stacked one.My question is what is the structure of the data which i should pass to data parameter. I have try passing an array, like(from google charts samples)

[['Genre', 'Fantasy & Sci Fi', 'Romance', 'Mystery/Crime', 'General','Western', 'Literature', { role: 'annotation' } ],['2010', 10, 24, 20, 32, 18, 5, '']]

but it didn't work.


回答1:


You can replicate Stacked Bar Charts like this:

data = [
  {
    name: "Fantasy & Sci Fi", 
    data: [["2010", 10], ["2020", 16], ["2030", 28]]
  },
  {
    name: "Romance", 
    data: [["2010", 24], ["2020", 22], ["2030", 19]]
  },
  {
    name: "Mystery/Crime", 
    data: [["2010", 20], ["2020", 23], ["2030", 29]]
  }
]

And in the template:

<%= bar_chart data, stacked: true %> 


来源:https://stackoverflow.com/questions/23947893/rails-chartkick-stacked-bar-charts

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