Rails chartkick stacked bar charts

后端 未结 2 398
生来不讨喜
生来不讨喜 2020-12-31 07:05

I\'m trying to create a stacked bar chart using Rails Chartkick gem and I\'m using Google charts API.

I have use this line to generate the bar chart using chartkick.

相关标签:
2条回答
  • 2020-12-31 07:16

    Use this format

    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]]
      }
    ]
    
    0 讨论(0)
  • 2020-12-31 07:23

    You can replicate Stacked Bar Charts like this:

    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]]
      }
    ]
    

    And in the template:

    <%= bar_chart data, stacked: true %> 
    
    0 讨论(0)
提交回复
热议问题