Reputation: 485
i am having Problems with Google Scatter Chart. The data contains user and their ratings for specific pictures. On the hAxis i have the users listed, on vAxis their rating. I create 15 different Scatter Charts, for half of them the hAxis is working, for some it will display +5 or +3 (e.g. 20 instead of 15) - Number of users and Scatter Charts just coincidence right now. Sometimes it starts at 0, sometimes at 1. Here you can see the output code in the Browser:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['User', 'Rating'],
[ 1, 5],
[ 2, 3],
[ 3, 3],
[ 4, 5],
[ 5, 2],
[ 6, 1],
[ 7, 4],
[ 8, 4],
[ 9, 1],
[ 10, 1],
[ 11, 10],
[ 12, 2],
[ 13, 5],
[ 14, 4],
[ 15, 3],
]);
var options = {
title: 'User and their ratings - Picture 6 (15 Ratings)',
hAxis: {title: 'User', minValue: 1, maxValue: 15},
vAxis: {title: 'Rating', minValue: 1, maxValue: 10},
legend: 'none'
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
This is my php Script:
$query = "SELECT rate FROM rating WHERE bild = '$bild_i' ";
$result = mysql_query($query) or die(mysql_error());
$menge = mysql_num_rows($result);
echo'<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
[\'User\', \'Rating\'],';
$i = 1;
while($row = mysql_fetch_array($result)) {
echo'
[ '.$i.', '.$row['rate'].'],
'; $i++;
}
echo'
]);
var options = {
title: \'User and their ratings - Picture '.$bild_i.' ('.$menge.' Ratings)\',
hAxis: {title: \'User\', minValue: 1, maxValue: '.$menge.'},
vAxis: {title: \'Rating\', minValue: 1, maxValue: 10},
legend: \'none\'
};
I have already tried some suggestions with the hAxis.viewWindowMode command, but it will display the same. Btw. the ('.$menge.' Ratings) always displays the correct number of user. Can somebody help?
Thanks!
Upvotes: 0
Views: 7543
Reputation: 26340
If you want that hAxis to span a specific range, then you need to use the hAxis.viewWindow.min/max
options:
hAxis: {
viewWindow: {
min: 0,
max: 20
}
}
Upvotes: 2