Chartkick column charts multiple colors

前端 未结 3 2018
日久生厌
日久生厌 2021-01-05 19:13

I\'m using chartckick in my RoR project to generate charts, which works quite nice. (along with Google Charts).

I\'ve created a column chart with only 2 bars

3条回答
  •  醉酒成梦
    2021-01-05 19:38

    From @buren's comment on GitHub it seems that using a different JSON structure will invoke different colors on the column_cart.


    I changed the output in the Helper:

    def parse_gender_data(data)
      gender_data = Hash.new
      gender_data[:male] = data[1]
      gender_data[:female] = data[2]
      [{"name" => "Male","data" => {"Gender" => gender_data[:male]}},{"name" => "Female","data" => {"Gender" => gender_data[:female]}}]
    end
    

    And created the chartkick.rb config file (config/initializers/chartkick.rb), adding some colors:

    Chartkick.options = {
      colors: ["#63b598", "#ce7d78", "#ea9e70", "#a48a9e", "#c6e1e8"]
    }
    


    Which outputs the desiring result:

    enter image description here

提交回复
热议问题