Ruby on rails 3 惰性高图表:更改饼图的颜色[rails 3]

Ruby on rails 3 惰性高图表:更改饼图的颜色[rails 3],ruby-on-rails-3,rubygems,charts,pie-chart,Ruby On Rails 3,Rubygems,Charts,Pie Chart,我在一个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

我在一个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
def set_饼图(数据)
固定_数据=[]
data.u每对do |键、值|
修正了数据“饼图”:边距=>[0,0,0,0]})
系列={
键入“pie”,
名称:'总费用',
数据:固定数据,
颜色:[“绿色”、“红色”]#
}
c、 系列(系列)
c、 颜色=[“红色”、“蓝色”、“黑色”]#
c、 选项[:颜色]=“绿色”、“蓝色”、“黄色”]#
c、 选项['colors']=['red'、'blue'、'yellow']#意图
c、 选项[:标题][:文本]=nil
c、 绘图选项(:饼图=>{
光标:“指针”,
中心:['50%,'37%,],
颜色:“红色”#
数据标签:{已启用:错误}
})
结束
结束
这个方法不会留下任何错误,正确的方法是什么,或者这个gem不可能


或者我可以在我的项目中使用其他什么好的替代宝石?

我也遇到了同样的问题,我通过将颜色选项放在视图中解决了这个问题。这就是我所做的:

#my_view_helper.rb
def chart_colors
  html =  
     "[{linearGradient: [0, 0, 0, 200], stops: [[0, '#e28b02'],[1, '#f1bc70']]},
     {linearGradient: [0, 0, 0, 200], stops: [[0, '#a5ba57'],[1, '#a8bb51']]}, 
     {linearGradient: [0, 0, 0, 200], stops: [[0, '#1e93d6'],[1, '#35aff6']]}, 
     {linearGradient: [0, 0, 0, 200], stops: [[0, '#c8cf99'],[1, '#cdcfa9']]}, 
     {linearGradient: [0, 0, 0, 200], stops: [[0, '#709ab1'],[1, '#a7c5d0']]}, 
     {linearGradient: [0, 0, 0, 200], stops: [[0, '#c76f4e'],[1, '#fba98e']]},
     {linearGradient: [0, 0, 0, 200], stops: [[0, '#95d6e3'],[1, '#bbe8ed']]}]"
  html
 end

#my_view.html.haml
#chart
  = high_chart("pie_1", @chart) do |c| 
    = "options.colors = #{chart_colors}".html_safe
@chart = LazyHighCharts::HighChart.new('pie') do |c|
    c.colors(["red","green","blue"]);
end