Annotating bars using Google Chart API -


i'm trying add annotations horizontal bars similar annotations in attached chart image. [eg: annotation bar '1' "7.4% (+2.4/ -.19)", bar '3' "11.7% (+2.9/ -2.4)" , average vertical line representation in image].

i have used bar chart , configured it's options render bars , interval. but, google charts api documentation, bar chart won't support annotation/ annotationtext in role.

which chart have choose google chart api? options have configure mark annotation? there example explains problem using google chart api?

the image excerpt google consumer survey page (http://www.google.com/insights/consumersurveys/view?survey=xirgjukonszvg&question=9&subpop&subpop).

thanks !

bar chart example

there no way create chart displayed in google visualization. can create error bars using datatable roles, barchart not support annotations (meaning can't have text on chart in example posted).

you can fiddle combochart, can support annotations, stuck column chart (not bar chart).

here code barchart:

function drawvisualization() {   // create , populate data table.   var data = new google.visualization.datatable();   data.addcolumn({type:'string', label:'label'});   data.addcolumn({type:'number', label:'value', pattern:'#.#%'});   data.addcolumn({type:'number', role:'interval', pattern:'#.#%'});  // interval role col.   data.addcolumn({type:'number', role:'interval', pattern:'#.#%'});  // interval role col.   data.addcolumn({type:'string', role:'annotation'}); // annotation role col. -- not enabled bar charts   data.addcolumn({type:'string', role:'annotationtext'}); // annotationtext col. -- not enabled bar charts   data.addrows([     ['1', 0.074, 0.055, 0.098, 'a', '7.4% (-1.9/2.4)'],     ['2', 0.04, 0.027, 0.059, 'b', '4.0% (-1.3/1.9)'],     ['3', 0.117, 0.093, 0.146, 'c', '11.7% (-2.4/2.9)'],     ['4', 0.217, 0.185, 0.252, 'd', '21.7% (-3.2/3.5)'],     ['5', 0.552, 0.511, 0.592, 'e', '55.2% (-4.1/4.0)'],   ]);    // create , draw visualization.   new google.visualization.barchart(document.getelementbyid('visualization')).     draw(data,          {title:"subpopulation b",           width:600, height:400,           vaxis: {title: "importance"},           haxis: {title: "percent", format:'#%'},          }         ); } 

here code combochart version:

function drawvisualization() {   // create , populate data table.   var data = new google.visualization.datatable();   data.addcolumn({type:'string', label:'label'});   data.addcolumn({type:'number', label:'value', pattern:'#.#%'});   data.addcolumn({type:'number', label:'line', pattern:'#.#%'});   data.addcolumn({type:'number', role:'interval', pattern:'#.#%'});  // interval role col.   data.addcolumn({type:'number', role:'interval', pattern:'#.#%'});  // interval role col.   data.addcolumn({type:'string', role:'annotation'}); // annotation role col. -- not enabled bar charts   data.addcolumn({type:'string', role:'annotationtext'}); // annotationtext col. -- not enabled bar charts   data.addrows([     ['1', 0.074, 0.074, 0.055, 0.098, '7.4% (-1.9/2.4)', '7.4% (-1.9/2.4)'],     ['2', 0.040, 0.040, 0.027, 0.059, '4.0% (-1.3/1.9)', '4.0% (-1.3/1.9)'],     ['3', 0.117, 0.117, 0.093, 0.146, '11.7% (-2.4/2.9)', '11.7% (-2.4/2.9)'],     ['4', 0.217, 0.217, 0.185, 0.252, '21.7% (-3.2/3.5)', '21.7% (-3.2/3.5)'],     ['5', 0.552, 0.552, 0.511, 0.592, '55.2% (-4.1/4.0)', '55.2% (-4.1/4.0)'],   ]);    // create , draw visualization.   var ac = new google.visualization.combochart(document.getelementbyid('visualization'));   ac.draw(data, {     title : 'subpopulation b',     width: 600,     height: 400,     vaxis: {title: "percentage", format:'#%'},     haxis: {title: "importance"},     seriestype: "bars",     series: {1: {type: "line"}}   }); } 

you can hide line using options, , make bit prettier, in general it's going similar (it isn't pretty sample).

if neither of these okay you, need write custom javascript add tooltips (annotations) barchart manually. don't know how (as no javascript expert), i'll leave if above workarounds aren't enough.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -