There is currently no way to create the chart displayed in google visualization. You can create error bars using DataTable Roles, but BarChart
does not support annotations (meaning you can't have the text on the chart as in the example you posted).
You can fiddle with a ComboChart
, which can support annotations, but then you get stuck with a column chart (not a bar chart).
Here is code for a barchart:
function drawVisualization() {
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:'#.#%'});
data.addColumn({type:'number', role:'interval', pattern:'#.#%'});
data.addColumn({type:'string', role:'annotation'});
data.addColumn({type:'string', role:'annotationText'});
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)'],
]);
new google.visualization.BarChart(document.getElementById('visualization')).
draw(data,
{title:"SubPopulation B",
width:600, height:400,
vAxis: {title: "Importance"},
hAxis: {title: "Percent", format:'#%'},
}
);
}
Here is code for a comboChart version:
function drawVisualization() {
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:'#.#%'});
data.addColumn({type:'number', role:'interval', pattern:'#.#%'});
data.addColumn({type:'string', role:'annotation'});
data.addColumn({type:'string', role:'annotationText'});
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)'],
]);
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 the line using the options, and make it look a bit prettier, but in general it's going to look similar (it isn't as pretty as your sample).
If neither of these are okay for you, then you will need to write custom javascript to add tooltips (annotations) to the BarChart
manually. I don't know how (as I am no javascript expert), so I'll leave that up to you if the above workarounds aren't good enough.