2つの異なるデータソースを持つ2つの異なるグラフを表示しようとしています。私の2番目の関数drawChart3()は、最初のチャートとそのデータソースを上書きします。私は緩和するために時間リスナーを追加しようとしましたが、私は失敗しました。私はJavaScriptにはかなり新しいので、私のエラーが存在する可能性のあるヒントを感謝します。 おかげGoogleグラフの2番目のデータが最初のデータとグラフを上書きする
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
google.setOnLoadCallback(drawChart3);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1ODIBoKW3H9bLNR2RnyfEqd9c0fzWaql1FfRp_JCWCyY/edit#gid=0');
query.setQuery('select *');
query.send(handleQueryResponse);
}
function drawChart3() {
var query3 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1yiNn3oQYYK4Z1aCl5R2pGqFcZLU66uFA1tqW69sGrOg/edit#gid=0');
query3.setQuery('select *');
query3.send(handleQueryResponse);
}
//Set chart options
var options = {'title': '^VIX Close & XX Correlation Coefficient',
'legend': {position: 'none'},
'width': 600,
'height': 300};
//Set chart options
var options3 = {'title': 'Search Queries: "XX", "Algorithmic Trading", "Trading", "Options"',
'legend': 'bottom',
chartArea:{left:60,top:50,width:'98%',height:'75%'},
'width': 1300,
'height': 500};
function handleQueryResponse(response) {
var data = response.getDataTable();
var chart = new google.visualization.AreaChart(document.getElementById('chart-container'));
google.visualization.events.addOneTimeListener(chart, 'ready', function() {
var chart3 = new google.visualization.AreaChart(document.getElementById('chart3-container'));
var data3 = response.getDataTable();
chart3.draw(data3, options3);
});
chart.draw(data, options);
}
</script>
</head>
<body>
<td><div id="chart-container" style="border: 1px solid #ccc"></div></td>
<td><div id="chart3-container" style="border: 1px solid #ccc"></div></td>
</body>
</html>
あなたのロジックはオフだと思います。 'response.getDataTable()'は 'data'と' data3'の間で変更されないので、上書きします。あなたはあなたのロジックを再加工する必要があります。 –