Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Anne Hennegar
Anne Hennegar
9,164 Points

How to change the bar color in a Google column chart?

I created a column chart using Google's Chart API. It's similar to the Sales and expenses one they have at: https://developers.google.com/chart/interactive/docs/gallery/columnchart#Colors

What I can't figure out from the documentation is how to change the "Expenses" column to another color. I see where they've changed column colors when the items are unique, but not when they're part of a series.

I tried using { role: 'style' } in JS Fiddler but can't get it to work so I'm guessing I'm putting it in the wrong place.

Thanks in advance

2 Answers

Hi Anne,

You can find out how to change this if you look at the "series" property in the "Configuration Options" table here: https://developers.google.com/chart/interactive/docs/gallery/columnchart#Configuration_Options

I don't know if you already have an options object set up but you would add the "series" property to it and then set it to whichever things you need to change as shown in that table.

I saved the fiddle example they have there showing how to change the color on the 2nd series "Expenses" to lightgray

http://jsfiddle.net/0khxgLj5/

The code shows both ways to specify the series value.

Nested objects - series: { 1: {color: 'lightgray'} }

Or an array of objects - series: [ {}, {color: 'lightgray'} ] Here you need an empty object in the first spot to indicate default values for the blue series.

Let me know if you have any questions about this.

Anne Hennegar
Anne Hennegar
9,164 Points

Jason,

thanks your Fiddler example was what I needed. I was unclear where I needed to add the color line. Much appreciated.