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
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:
And created the
chartkick.rb
config file (config/initializers/chartkick.rb
), adding some colors:Which outputs the desiring result: