Hey guys,
I'm showing 3 small charts - pie, colum and geo on the same page. Here
is my code:
<script src="
https://www.google.com/jsapi" type="text/javascript"></
script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart", 'geochart',
'imagechart']});
google.setOnLoadCallback(drawPie);
google.setOnLoadCallback(drawColumn);
google.setOnLoadCallback(drawMap);
function drawPie() {
var age = [{"count":"2","age":"24"},{"count":"1","age":"30"},
{"count":"1","age":"40"}];
var data = new google.visualization.DataTable();
data.addColumn('string', 'Age');
data.addColumn('number', 'Number of people');
data.addRows(age.length);
var i = 0;
age.each(function(user) {
data.setValue(i, 0, user.age.toString());
data.setValue(i, 1, user.count.toInt());
i++;
});
var chart = new
google.visualization.PieChart(document.getElementById('age'));
chart.draw(data, {width: 450, height: 300, title: 'Age'});
google.visualization.events.addListener(chart, 'select', function()
{
var selection = chart.getSelection();
var age = data.getValue(selection[0].row,0);
window.location = 'index.php?
option=com_rapleaf&view=users&search=age:' + age;
});
// var options = {cht: 'p', title: 'Age', chp: 0.628, chs:
'400x200'};
// var chart = new
google.visualization.ImageChart(document.getElementById('pie_div'));
// chart.draw(data, options);
}
function drawColumn() {
var gender = [{"age":24,"male":"1","female":"1"},{"age":
30,"male":"1","female":0},{"age":40,"male":0,"female":"1"}];
var data = new google.visualization.DataTable();
data.addColumn('string', 'Age');
data.addColumn('number', 'Male');
data.addColumn('number', 'Female');
data.addRows(gender.length);
var i = 0;
gender.each(function(user) {
data.setValue(i, 0, user.age.toString());
data.setValue(i, 1, user.male.toInt());
data.setValue(i, 2, user.female.toInt());
i++;
});
var genderChart = new
google.visualization.ColumnChart(document.getElementById('gender'));
genderChart.draw(data, {width: 450, height: 300, title: 'Gender',
hAxis: {title: 'Age', titleTextStyle: {color: 'red'}}});
google.visualization.events.addListener(genderChart, 'select',
function() {
var selection = genderChart.getSelection();
var gender = data.getValue(selection[0].row,0);
window.location = 'index.php?
option=com_rapleaf&view=users&search=gender:' + gender;
});
}
function drawMap() {
var location = [{"count":"1","location":"Germany"},
{"count":"1","location":"Paris, France"},
{"count":"2","location":"Spain"}];
var mapData = new google.visualization.DataTable();
mapData.addColumn('string', 'Country');
mapData.addColumn('number', 'Users');
mapData.addRows(location.length);
var i = 0;
location.each(function(country) {
mapData.setValue(i, 0, country.location);
mapData.setValue(i, 1, country.count.toInt());
i++;
});
var options = {width: 556, height: 347};
var container = document.getElementById('map');
var geochart = new google.visualization.GeoChart(container);
geochart.draw(mapData, options);
google.visualization.events.addListener(geochart, 'select',
function() {
// var selection = geochart.getSelection();
// var location = mapData.getValue(selection[0].row,0);
// window.location = 'index.php?
option=com_rapleaf&view=users&search=location:' + location;
});
}
</script>
The charts are displayed, but the pie and column one are missing the
tooltips. Moreover I have a listener for select, but it also doesn't
work.
When I remove the geoChart, then I get the expected result from the
pie and column charts...
Any ideas what am I doing wrong here?