Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mulitple colors in bar chart #149

Closed
jdubhub opened this issue Dec 2, 2014 · 8 comments
Closed

Mulitple colors in bar chart #149

jdubhub opened this issue Dec 2, 2014 · 8 comments

Comments

@jdubhub
Copy link

jdubhub commented Dec 2, 2014

Perhaps this is more a support question rather than a bug, I'm trying to create a multicoloured colum_chart. I can't seem to set different colours for each series. Can you please advise where the issue is. Thankyou

  `  <%= column_chart  [
    ["Deferred", @repair.deferred_count],
    ["Monitored", @repair.monitor_count],
    ["Important", @repair.important_count],
    ["Urgent", @repair.urgent_count],
  ],
    colors: ["#00639c", "blue","yellow", "red"],
    :height => "210px", 
    :library => {
      :backgroundColor => "#002f4c",
      :chartArea => {:width =>'100%', :height => '100%'},
      :legend => "none",
      :vAxis => { :gridlines => {:color => "#002f4c"}, :baselineColor =>  "002f4c"}
    } %> `
@MegatronCupcakes
Copy link

library: {series: {0 => {color: 'pink'}, 1 => {color: 'purple'}, 2 => {color: 'yellow'}}

@jdubhub
Copy link
Author

jdubhub commented Dec 15, 2014

Thanks for that MegatronCupcakes.

I've updated the code to the following however per the attached screenshot,
all series are still appearing as one colour.

(using Chrome on Yosemite)

Regards,

[image: 3sparks llc] http://www.easy2use.com.au/

Jared Winton
0409 202 203/ jared@easy2use.com.au

Office: *1800 100 941 */ Fax: 02 8580 6363
05 Peter Brock Drive, Oran Park Town NSW 2570

On 13 December 2014 at 03:01, MegatronCupcakes notifications@github.com
wrote:

library: {series: {0 => {color: 'pink'}, 1 => {color: 'purple'}, 2 =>
{color: 'yellow'}}


Reply to this email directly or view it on GitHub
#149 (comment).

@adelivuk-zz
Copy link

I can also confirm that this doesn't work - it just uses the first value for all columns.

Is there a way to specify a different color for each column?

@buren
Copy link

buren commented Jan 18, 2015

@adelivuk, @jdubhub
I've created bar/column charts with different colours with this code:

# charts/gender.html.erb
column_chart(charts_gender_path)

And charts_gender_path answers with this JSON:

[{"name":"Male","data":{"Gender":38}},{"name":"Female","data":{"Gender":59}}]

@adelivuk-zz
Copy link

I can confirm that @buren JSON structure will use different color for the column_cart.

Just a note, you have to first speficy the colors in your config/initializers/chartkick.rb:

Chartkick.options = {
  colors: ["#color1", "#color2", "#color3", "#color4", "#color5"]
}

@leonardk1
Copy link

@buren It has worked for me, and yes you have to specify the colors as @adelivuk has pointed out

@leonardk1
Copy link

however I had to edit this
[{"name":"Male","data":{"Gender":38}},{"name":"Female","data":{"Gender":59}}] to
[{name: "Male", data: {"Gender": 38}}, {name: "Female", data: {"Gender": 59 } }]

to use the new supported hash structure

@ankane
Copy link
Owner

ankane commented Jan 7, 2017

Sounds like this was solved. For future readers, you can use the multiple series format for different colors for the bars.

@ankane ankane closed this as completed Jan 7, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants