I have successfully created a diff scatter chart following the examples in the guides from data which is hardcoded into the function (as in the google guides). However, replacing the data with calls to google sheets will only draw the two data charts but not the diff chart.
The code is below (apologies, i am not a programmer so this might be a bit more messy than usual) and the sheets is open to test.I have tried it with separate draw functions (some of the commented out lines) or with all in one function which does not make a difference in the hardcoded data but also has not impact here.
I am wondering what i have missed or whether diff charts simply do not work with external data sources.
Many thanks, Uwe
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="
https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
//This is written in 'classic' style as most options are not yet implemented in the 'material' style
//Load the Visualization API and the corechart package.
google.charts.load('current', {'packages':['corechart', 'table'], 'language': 'de'});// the language setting to DE is a simple way to get at 24 hour time format for the x axis :-)
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChartoriginal);
//google.charts.setOnLoadCallback(drawChartnew);
//google.charts.setOnLoadCallback(drawChartDiff);
function drawChartoriginal() {
//the next line is the link to the Google Sheets which is the following URL and which needs to be subtly changed
//in the format at the end of the link:
https://docs.google.com/spreadsheets/d/1xzoNFEuwHilog2zNjuKuilUXbHKCFWNHGZsS2zwEojs/edit#gid=678810481.
var queryoriginal = new google.visualization.Query('
http://docs.google.com/spreadsheet/tq?key=135RNRlBakQ5aXqsABZpmLE9dVWjt9tZiWdCwD3e9RS4&gid=161902447');
queryoriginal.setQuery('SELECT A, B');//this selects the columns from the spreadsheet
queryoriginal.send(function (responseoriginal) {
if (responseoriginal.isError()) {
alert('Error in query: ' + responseoriginal.getMessage() + ' ' + responseoriginal.getDetailedMessage());
return;
}
var dataoriginal = responseoriginal.getDataTable();
var chartoriginal = new google.visualization.ScatterChart(document.getElementById('chartoriginal_div'));
chartoriginal.draw(dataoriginal);
});
//function drawChartnew() {
var querynew = new google.visualization.Query('
http://docs.google.com/spreadsheet/tq?key=135RNRlBakQ5aXqsABZpmLE9dVWjt9tZiWdCwD3e9RS4&gid=161902447');
querynew.setQuery('SELECT A, C');//this selects the columns from the spreadsheet
querynew.send(function (responsenew) {
if (responsenew.isError()) {
alert('Error in query: ' + responsenew.getMessage() + ' ' + responsenew.getDetailedMessage());
return;
}
var datanew = responsenew.getDataTable();
var chartnew = new google.visualization.ScatterChart(document.getElementById('chartnew_div'));
chartnew.draw(datanew);
});
//function drawChartDiff() {
var chartDiff = new google.visualization.ScatterChart(document.getElementById('chartdiff_div'));
var diffData = chartDiff.computeDiff(dataoriginal, datanew);
chartDiff.draw(diffData);
//};
};
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chartoriginal_div"></div>
Data:
<div id="chartnew_div"></div>
differencegraph
<div id="chartdiff_div"></div>
</body>
</html>