Rails chartkick堆叠条形图 [英] Rails chartkick stacked bar charts
本文介绍了Rails chartkick堆叠条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Rails Chartkick gem创建一个堆叠条形图,我正在使用Google图表API。
I'm trying to create a stacked bar chart using Rails Chartkick gem and I'm using Google charts API.
我使用这一行来使用chartkick生成条形图。
I have use this line to generate the bar chart using chartkick.
<%= bar_chart data, :library => {:isStacked => true} %>
但是我得到的是一个简单的条形图而不是堆叠的一个。我的问题是什么是我应该传递给 data
参数的数据结构。我尝试传递一个数组,像(从谷歌图表样本)
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, '']]
但不起作用。
推荐答案
您可以复制堆叠栏图表如下:
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]]
}
]
在模板中:
<%= bar_chart data, stacked: true %>
这篇关于Rails chartkick堆叠条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文