Javascript 具有不同数据集的多个Google图表
我在同一个.html页面上有两个条形图,但第一个条形图覆盖了第二个条形图。仅显示过一个图表。我不想使用iframe,我已经使函数/变量具有唯一性。我还缺什么Javascript 具有不同数据集的多个Google图表,javascript,google-visualization,Javascript,Google Visualization,我在同一个.html页面上有两个条形图,但第一个条形图覆盖了第二个条形图。仅显示过一个图表。我不想使用iframe,我已经使函数/变量具有唯一性。我还缺什么 <script type="text/javascript"> // Load the Visualization API and the piechart package. google.charts.load('current', {'packages':['corechart']}); // Set a call
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawCycleStatusChart);
function drawCycleStatusChart() {
var jsonCycleData = $.ajax({
url: "cycleStatus.php",
dataType: "json",
async: false
}).responseText;
var jsonCycleObj = eval(jsonCycleData);
console.log(typeof jsonCycleData);
// Create our data table out of JSON data loaded from server.
var dataCycle = new google.visualization.arrayToDataTable(jsonCycleObj);
var optionsCycle = {
//isStacked: 'percent',
orientation: 'horizontal',
height: 600,
chartArea: {height: 500},
width: '100%',
fontName: 'Arial',
fontSize: 15,
annotations: {
textStyle: {fontSize: 10, fontName: 'Calibri'}
},
legend: {position: 'top', maxLines: 4},
hAxis: {
minValue: 0,
//title: 'Web UI Release Night Test Cycles in Production',
//titleTextStyle: {fontSize: 25, bold: true},
textStyle: {fontSize: 15, bold: false}
}
};
// Instantiate and draw our chart, passing in some options.
var chartCycle = new google.visualization.ColumnChart(document.getElementById('cycle_status'));
chartCycle.draw(dataCycle, optionsCycle);
}
//加载可视化API和piechart包。
load('current',{'packages':['corechart']});
//将回调设置为在加载Google Visualization API时运行。
setOnLoadCallback(drawCycleStatusChart);
函数drawCycleStatusChart(){
var jsonCycleData=$.ajax({
url:“cycleStatus.php”,
数据类型:“json”,
异步:false
}).responseText;
var jsonCycleObj=eval(jsonCycleData);
console.log(jsonCycleData类型);
//使用从服务器加载的JSON数据创建我们的数据表。
var dataCycle=new google.visualization.arrayToDataTable(jsonCycleObj);
var optionsCycle={
//它的标题是:'百分比',
方向:“水平”,
身高:600,
图表区域:{高度:500},
宽度:“100%”,
字体名称:“Arial”,
尺寸:15,
注释:{
textStyle:{fontSize:10,fontName:'Calibri'}
},
图例:{位置:'top',最大行数:4},
哈克斯:{
最小值:0,
//标题:“生产中的Web UI发布夜间测试周期”,
//titleTextStyle:{fontSize:25,粗体:true},
textStyle:{fontSize:15,粗体:false}
}
};
//实例化并绘制图表,传入一些选项。
var chartCycle=new google.visualization.ColumnChart(document.getElementById('cycle_status'));
chartCycle.draw(数据周期、选项周期);
}
//加载可视化API和piechart包。
load('current',{'packages':['corechart']});
//将回调设置为在加载Google Visualization API时运行。
google.charts.setOnLoadCallback(drawChart);
函数绘图图(){
var jsonData=$.ajax({
url:“executionStatus.php”,
数据类型:“json”,
异步:false
}).responseText;
var jsonObj=eval(jsonData);
console.log(jsonData类型);
//使用从服务器加载的JSON数据创建我们的数据表。
var data=新的google.visualization.arrayToDataTable(jsonObj);
变量选项={
它的标题是:'百分比',
方向:“水平”,
身高:600,
图表区:{高度:300},
//宽度:“100%”,
字体名称:“Arial”,
尺寸:15,
注释:{
textStyle:{fontSize:10,fontName:'Calibri'}
},
图例:{位置:'top',最大行数:4},
哈克斯:{
最小值:0,
//标题:“生产中的Web UI发布夜间测试周期”,
//titleTextStyle:{fontSize:25,粗体:true},
textStyle:{fontSize:15,粗体:false}
}
};
//实例化并绘制图表,传入一些选项。
var chart=new google.visualization.ColumnChart(document.getElementById('stacked_bar'));
图表绘制(数据、选项);
}
缺少结束>标记发现了我的错误!你应该把它贴在这里,以方便其他人或删除该问题
// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "executionStatus.php",
dataType: "json",
async: false
}).responseText;
var jsonObj = eval(jsonData);
console.log(typeof jsonData);
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.arrayToDataTable(jsonObj);
var options = {
isStacked: 'percent',
orientation: 'horizontal',
height: 600,
chartArea: {height: 300},
//width: '100%',
fontName: 'Arial',
fontSize: 15,
annotations: {
textStyle: {fontSize: 10, fontName: 'Calibri'}
},
legend: {position: 'top', maxLines: 4},
hAxis: {
minValue: 0,
//title: 'Web UI Release Night Test Cycles in Production',
//titleTextStyle: {fontSize: 25, bold: true},
textStyle: {fontSize: 15, bold: false}
}
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById('stacked_bar'));
chart.draw(data, options);
}
</script>
<div id="cycle_status"</div>
<div id="stacked_bar"></div>
<div id="cycle_status"></div>