Bar charts with different colors for negative values

6,920 views
Skip to first unread message

tim

unread,
Apr 13, 2011, 9:29:57 PM4/13/11
to Google Chart API
I don't see anything in the API changing the color of the bar
depending on the value. Is there a way to make it so that negative
values are different color than positive ones?

Thanks.

duniyadnd

unread,
Apr 14, 2011, 8:41:20 AM4/14/11
to google-c...@googlegroups.com
Hi Tim,

Did you try this with stacked charts?

KeithB

unread,
Apr 14, 2011, 1:53:05 PM4/14/11
to google-c...@googlegroups.com
No, the API does not support that sort of styling rule, sorry.

David Nicol

unread,
Apr 14, 2011, 3:30:18 PM4/14/11
to google-c...@googlegroups.com
you could do it with stacked but it would take some preprocessing

duniyadnd

unread,
Apr 14, 2011, 3:47:03 PM4/14/11
to google-c...@googlegroups.com
Example

You can remove the axis through this trick

Tim Uckun

unread,
Apr 14, 2011, 4:05:59 PM4/14/11
to google-c...@googlegroups.com
On Fri, Apr 15, 2011 at 7:30 AM, David Nicol <david...@gmail.com> wrote:
> you could do it with stacked but it would take some preprocessing

There is only one set of values but I guess I can separate the
negative values into another series and paint them another color.

Viktor Dimitrov

unread,
Sep 9, 2015, 8:50:07 AM9/9/15
to Google Chart API, timu...@gmail.com
I wrote a script for areachart but I think the solution is similar. I hope it would be helpful.

Tim Korhumel

unread,
Jun 2, 2016, 11:59:01 AM6/2/16
to Google Chart API
How would I go about implementing this script into an area chart that I have already generated?  Specifically just the portion that colors the lines and the area based on the positive/negative value?

Daniel LaLiberte

unread,
Jun 2, 2016, 12:15:55 PM6/2/16
to google-c...@googlegroups.com
There is no option to just color negative areas differently, although that would be a good idea.  

But you can get a similar effect by filling the negative area with another area chart.  Here is a modification of the previously posted example that does that:  http://jsfiddle.net/bnugqpjx/6/

--
You received this message because you are subscribed to the Google Groups "Google Chart API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chart-a...@googlegroups.com.
To post to this group, send email to google-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-chart-api.

For more options, visit https://groups.google.com/d/optout.



--

Tim

unread,
Jun 2, 2016, 12:55:58 PM6/2/16
to Google Chart API
Thanks for the quick reply Dan.  I was hoping that I could use Viktor's script to modify my current chart, or to generate a chart with my current data.  I've found a somewhat simpler solution that fits my need.


I just made two copies of the same chart and made them inside a worksheet.  One copy is on top with axis setup for only positive values (with a green line and area), the other is in front of it and axis setup for only negative values (with the data line formatted red with a red area).  Then I adjusted the size of the plot area so that the "negative" chart's plot area extended all the way to the top of the chart.  The bottom of the "positive" chart is covered up by the "negative" chart making it looks like a single chart with green = positive and red = negative.

Sorry for hijacking the thread everyone (also sorry for posting this all as it turns out my problem is more of a Google Sheets thing instead of Charts API).
positive + negative charts separated.png
positive + negative charts together.png

Kevin French

unread,
Jan 26, 2018, 10:05:24 AM1/26/18
to Google Chart API
Thanks for this! It helped me with the same dilemma. Although just note to make sure the graphs are the same width and height to prevent any stretching.
Yes I know its 6/2/16 for the last post but hey! people searching to find this answer must know this important step.
Reply all
Reply to author
Forward
0 new messages