Chartkick column charts multiple colors

前端 未结 3 1997
日久生厌
日久生厌 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:40

    The following also works. I didn't need any new files in initializers (no chartkick.rb file), this just worked by adding the following code to my helper file:

      def networth_data
        [
          {name: "Assets", data: {"NetWorth": 6979.53}}, 
          {name: "Liabilities", data: {"NetWorth": 10532.32}}
        ]
      end
    

    And then in my html.erb i specified the colors and other options I wanted:

    <%= column_chart networth_data, 
      colors: ["green", "#FF0000"], 
      library: {backgroundColor: "#FFF", height: 265} %>
    

    ...renders this chart:

    enter image description here

提交回复
热议问题