Reputation: 63
i need to visualize the google chart with the average rating made for a products based on the 1 week, 2 Months, 4 Months, 8 Months and 12 Months, so i have tried to visualize it with the google visualization tool, so i got the following code there
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Duration', 'rating'],
['1 week', 1],
['2 Months', 2],
['4 Months', 3],
['8 Months', 4],
['1 Year', 5],
]);
// Create and draw the visualization.
new google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
width:600, height:400,
hAxis: {title: "Year"}}
);
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="visualization" style="width: 600px; height: 400px;"></div>
</body>
</html>
here it displaying the output as
i need the y axis must be 1 to 5 and in the x axis must have the average rating based on the time frame, is this is possible? what i have to do?
Upvotes: 1
Views: 669
Reputation: 16304
To answer the first part of the question...
...y axis must be 1 to 5...
... you have to format the y axis, which isn't in your code yet.
Change your call to google.visualization.ColumnChart
to
new google.visualization.ColumnChart(
document.getElementById('visualization')).draw(
data, {
title: "Yearly Coffee Consumption by Country",
width: 600,
height: 400,
hAxis: {
title: "Year"
},
vAxis: { <- new code from here...
minValue:0,
format:'#',
gridlines:{
count:6
}
}
}
);
This should format the axis according to your description.
The 2nd part of your question,
...the x axis must have the average rating based on the time frame...
is not yet clear to me. Please add some more detail to it, p.e. how / what kind of data do you want where.
Upvotes: 1