Lazy High Charts:更改饼图的颜色 [rails 3]
我正在 Rails 3 项目中工作,我想更改使用 LazyHighChart gem 生成的饼图颜色,但我不知道该怎么做
这是我的方法控制器,
def set_pie_chart(data)
fixed_data = []
data.each_pair do |key, value|
fixed_data << [key.name, value]
end
@color = data.keys.map {|e| "#" + e.colour } # e.colour is like '333333'
@chart = LazyHighCharts::HighChart.new('pie') do |c|
c.chart({:defaultSeriesType=>"pie" , :margin=> [0, 0, 0, 0]})
series = {
type: 'pie',
name: 'total expenses',
data: fixed_data,
colors: ['green','red'] # intent
}
c.series(series)
c.colors = ['red','blue','black'] # intent
c.options[:colors] = ['green','blue','yellow'] # intent
c.options['colors'] = ['red','blue','yellow'] # intent
c.options[:title][:text] = nil
c.plot_options(:pie=>{
cursor: "pointer",
center: ['50%','37%'],
color: 'red', #intent
dataLabels: { enabled: false }
})
end
end
此方法不会留下任何错误,什么这个宝石的方法是正确的还是不可能的?
或者我可以在我的项目中使用哪些其他好的替代宝石?
I'm working in a rails 3 project, I want to change the pie chart colors that I generate with the LazyHighChart gem and I don;t know how to do that
This is my method controller
def set_pie_chart(data)
fixed_data = []
data.each_pair do |key, value|
fixed_data << [key.name, value]
end
@color = data.keys.map {|e| "#" + e.colour } # e.colour is like '333333'
@chart = LazyHighCharts::HighChart.new('pie') do |c|
c.chart({:defaultSeriesType=>"pie" , :margin=> [0, 0, 0, 0]})
series = {
type: 'pie',
name: 'total expenses',
data: fixed_data,
colors: ['green','red'] # intent
}
c.series(series)
c.colors = ['red','blue','black'] # intent
c.options[:colors] = ['green','blue','yellow'] # intent
c.options['colors'] = ['red','blue','yellow'] # intent
c.options[:title][:text] = nil
c.plot_options(:pie=>{
cursor: "pointer",
center: ['50%','37%'],
color: 'red', #intent
dataLabels: { enabled: false }
})
end
end
this method doesn't leave any error, what is the correct way or its not possible with this gem?
or what other good alternative gems could I use for my project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我通过将颜色选项放在我的视图中解决了它。这就是我所做的:
I had the same problem and I solved it by putting the color options in my view. This is what I did: