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 (male and female).
And now the client wants that each bar have different color? Is that possible?
I've seen this post - How to change the color of a Column-chart created with Chartkick? but it's more then half of year old and I'm hoping that there is a way now to specify more colors to the bars.
Update
My code looks like:
Controller
@followers_gender_count = Project.find(params[:id]).followers.group(:gender).count
View
<%= column_chart parse_gender_data(@followers_gender_count) %>
Helper
def parse_gender_data(data)
gender_data = Hash.new
gender_data[:male] = data[1]
gender_data[:female] = data[2]
({ 'Male' => gender_data[:male], 'Female' => gender_data[:female] })
end
Update 2 - Issue on GitHub
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: