annotation with google combo chart

1,723 views
Skip to first unread message

Shyam Agarwal

unread,
Jun 14, 2013, 5:37:38 AM6/14/13
to google-visua...@googlegroups.com
Dear Sir,

I am new to Google Visualization. I have used combo chart of this api and its working very well. Now we want to show the value on each bar statically.  I have used annotation and annotationText property for this. But its shows value for only first bar in each group. I am not getting what i have missed.

Can anyone help me for this? Otherwise i have to look for other Charts API. But i don't want that.

Please help me asap.

Thanks
Shyam Agarwal

asgallant

unread,
Jun 14, 2013, 11:47:12 AM6/14/13
to google-visua...@googlegroups.com
If you post your code or a link to the page, I will take a look.

Shyam Agarwal

unread,
Oct 3, 2013, 9:38:40 AM10/3/13
to google-visua...@googlegroups.com
Please found the code here.
http://jsfiddle.net/QjQNX/183/

asgallant

unread,
Oct 3, 2013, 10:52:30 AM10/3/13
to google-visua...@googlegroups.com
There are a couple of things going on here.  First, annotations are applied to the columns immediately preceding them in the DataTable, so by adding them like this:

data.addColumn({type: 'string', role: 'annotation'});
data.addColumn({type: 'string', role: 'annotationText'});
data.addColumn('number', score[0]);


the annotations will apply to the previous column, not to the column created by data.addColumn('number', score[0]);.  This means that your first annotation columns are being applied to the domain column ("Year" in your example), which is why you see the numbers at the bottom of the central bars in each group.  To fix that, you would need to change the order of the columns:

data.addColumn('number', score[0]);

data.addColumn({type: 'string', role: 'annotation'});
data.addColumn({type: 'string', role: 'annotationText'});


The annotations don't show up for the bars because annotations are not supported with bars; they work with LineCharts and AreaCharts, and "line"/"area" series in ComboCharts (and maybe a few others that escape my memory at this time), but they don't work for BarCharts, ColumnCharts, CandleStickCharts, and "bar"/"candlestick" series in ComboCharts.

I wrote a hack that can fake annotations on "bar" series in a ComboChart (see http://jsfiddle.net/asgallant/QjQNX/); it doesn't work in all cases - specifically, it won't work well with columns that are side-by-side like the ones in your example.  If you can stack your columns (setting the chart's "isStacked" option to true), then this method might work.

Alexandre Carrie

unread,
Sep 24, 2014, 9:32:38 AM9/24/14
to google-visua...@googlegroups.com
Hello Andrew,
Today, can we put annotations on bars in combo chart?

Andrew Gallant

unread,
Sep 24, 2014, 7:20:27 PM9/24/14
to google-visua...@googlegroups.com
Yes, annotations are now supported on all bar-type charts (BarCharts, ColumnCharts, ComboCharts using "bars" type series).
Reply all
Reply to author
Forward
0 new messages