1
Hello,
I have a problem running a Google Chart Geochart map in Java...
If it’s in a normal . html file, it works, but inside my xhtml project it doesn’t work.
Code in html:
<html>
<head>
<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type='text/javascript'>
google.charts.load('current', {'packages': ['geochart']});
google.charts.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = google.visualization.arrayToDataTable([
['Cidade', 'Margem', 'Vendas'],
['Rio de Janeiro', 45000, 30],
['Porto Alegre', 72000, 50],
['São Paulo', 27000, 25],
['Santa Maria', 11000, 11]
]);
var options = {
region: 'BR',
displayMode: 'markers',
colorAxis: {colors: ['red', 'green']}
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Below the code in java:
<ui:define name="conteudo">
<div class="container">
<div class="row">
<div class="col-md-6 BorderedBox">
<div id="chart_div2" class="chart"></div>
</div>
</div>
<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type='text/javascript'>
google.charts.load('current', {'packages': ['geochart']});
google.charts.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = google.visualization.arrayToDataTable([
['Cidade', 'Margem', 'Vendas'],
['Rio de Janeiro', 45000, 30],
['Porto Alegre', 72000, 50],
['São Paulo', 27000, 25],
['Santa Maria', 11000, 11]
]);
var options = {
region: 'BR',
displayMode: 'markers',
colorAxis: {colors: ['red', 'green']}
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div2'));
chart.draw(data, options);
};
</script>
</div>
</ui:define>
The Map looks in Java, but all in white, without appearing the balls with the values set, Already in html appears the map with the colored balls.
Any error in console?
– BrTkCa
None... S unfortunately it just doesn’t bring the values.
– Raphão Torres
If the scripts are being loaded and the function is being called I don’t know what can be. Maybe the map is trying to be painted before the screen has been fully loaded, check this out.
– BrTkCa
At worst, if the map has some xabu for xhtml, you can leave it in an html itself and use a frame in xhtml :/
– BrTkCa
is a valid attempt, I have a pie chart and everything is ok, even connecting with the database, but this one, is complicated...
– Raphão Torres
What’s really going on is that you’re not carrying the values? city, margin and sale? is that it?
– Renato Vieira Dantas
That’s right Renato, the map is all white, without appearing the values. If I make the same code in a normal html (notepad), it loads and inserts the values...
– Raphão Torres