Reputation: 1315
I try to create bar chart using google chart example
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 5],
['Onions', 4],
['Olives', 3]
['Zucchini', 2],
['Pepperoni', 1]
]);
Chart is created successfully but on X-Axis it shows value from 0 to 6. When i pass all values as 0 it shows X-Axis from -1 to +1.
Is it possible to set X-Axis to always start from 0% to 100%.
Upvotes: 20
Views: 66742
Reputation: 3241
Set the tick
values:
vAxis: {
ticks: [{v:0, f:'0%'},{v:10, f:'10%'},{v:20, f:'20%'},{v:30, f:'30%'}]
}
Upvotes: 4
Reputation: 29
u can set x axis by modifing count value as we are using DataTable()
var databmi = new google.visualization.DataTable();
data.addColumn('string', 'Country');
data.addColumn('number', 'GDP');
data.addRows([
['US', 16768100],
['China', 9181204],
['Japan', 4898532],
['Germany', 3730261],
['France', 2678455]
]);
var options = {
title: 'GDP of selected countries, in US $millions',
width: 500,
height: 300,
legend: 'none',
bar: {groupWidth: '95%'},
vAxis: {
title :'your choice',
gridlines: { count: 4 }
},
hAxis: {
title :'your choice',
gridlines: {count: 4}
}
};
Upvotes: 2
Reputation: 26340
You can force the x-axis of a BarChart to always show a certain range by setting the hAxis.viewWindow.min
and hAxis.viewWindow.max
options:
hAxis: {
viewWindow: {
min: 0,
max: 100
},
ticks: [0, 25, 50, 75, 100] // display labels every 25
}
Upvotes: 52