Annotation style with JSON literal

483 views
Skip to first unread message

Amir Miller

unread,
Feb 8, 2012, 6:37:11 AM2/8/12
to google-visua...@googlegroups.com
Hi,

I am creating a chart with annotation.
I want the annotations to use a full line, so I am adding "annotation: {3: {style: 'line'}}" to my chart options.
This worked fine with the DataTable structure, but when I use JSON (which is how my data is structured) the annotation simply disappears.
If I remove the style from the chart options then the annotation reappears but is attached to one of the lines which is not what I want.
Here is my code:
var chartData = "{cols:["
chartData += "{id:'Date',label:'Date',type:'string',pattern:''},";
chartData += "{id:'aaa',label:'aaa',type:'number',pattern:''},";
chartData += "{id:'',label:'',pattern:'',type:'string',p:{role:'annotation'}},";
chartData += "{id:'',label:'',pattern:'',type:'string',p:{role:'annotationText'}}],";
chartData += "rows:[";
chartData += "{c:[{v:'2012-01-18'},{v:200},{v:'ann'},{v:'annText'}]},";
chartData += "{c:[{v:'2012-01-19'},{v:300}]}]}";
chartData = eval("("+chartData+")"); //Convert chart data str to json
var data = new google.visualization.DataTable(chartData);
data.setValue(1, 2, 'ann2');
data.setValue(1, 3, 'ann2Text');
      
// Create and draw the visualization.
var ac = new google.visualization.ComboChart(document.getElementById('visualization'));
ac.draw(data, {annotation: {3: {style: 'line'}}});

Can you please help me figure out if I'm doing something wrong or perhaps this is a bug in the API?

Thanks,

Amir.

Viz Kid

unread,
Feb 8, 2012, 7:16:23 AM2/8/12
to google-visua...@googlegroups.com

Line annotations are only supported on the domain and not on a specific series, as written here: http://code.google.com/apis/chart/interactive/docs/roles.html#annotationrole
If you would move these two columns to be right after the first date column, it should be ok.

  Viz Kid

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/Qah02Y0-BDkJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

Amir Miller

unread,
Feb 8, 2012, 7:59:55 AM2/8/12
to google-visua...@googlegroups.com
Thanks, I just figured this out myself and was going to reply.
You beat me to it :)

Anyhow, as you said, putting the annotations right after the first column works.
Reply all
Reply to author
Forward
0 new messages