点击谷歌可视化中的按钮后绘制图表
Drawing a chart after a click of a button in Google visualizaton
我正试图弄清楚如何在点击按钮后绘制图表。我的代码似乎有问题。我正在使用谷歌可视化和Javascript来完成这个活动。有人能看一下吗?
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript"
src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart','table','piechart','linechart','controls','charteditor']}]}">
</script>
<script type="text/javascript">
google.setOnLoadCallback(pieChart);
function pieChart() {
var pieJsonData = $.ajax({
url: "overall_ban_pos_pie_date.php?startdate=2012-01-01&enddate=2012-01-06",
dataType:"json",
async: false
}).responseText;
var pieData = new google.visualization.DataTable(pieJsonData);
var options = {chartArea:{left:10,top:40,height:200,width:360},
width:300,
height:260,
title: "Positive Contacts Percentage",
titleTextStyle:{fontSize:12},
tooltip:{showColorCode:true},
legend:{textStyle:{fontSize: 10},position:'left'},
pieSliceTextStyle:{fontSize: 10}}
var pieChartWrapper = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'pie_div',
'dataTable':pieData,
'options': options
});
}
google.visualization.events.addListener(pieChartWrapper, 'ready', selectHandler);
function selectHandler(e) {
pieChartWrapper.draw();
}
</script>
</head>
<body style="font-size:62.5%;">
<form>
Start Date: <input type="text" name="startdate" id="datepicker"/>
End Date: <input type="text" name="enddate" id="datepicker2"/>
<input type="button" value="click me!" onclick="pieChart();"/>
</form>
<div id="pie_div"></div>
</body>
</html>
此代码出现问题。
我想有一些副本&粘贴问题-下面的代码应该可以工作(我放了一些你可以忽略的测试数据)
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > < html xmlns = "http://www.w3.org/1999/xhtml" > < head >
< link href = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
rel = "stylesheet"
type = "text/css" / > < script type = "text/javascript"
src = "http://code.jquery.com/jquery-1.6.2.min.js" > < /script>
<script src="http:/ / ajax.googleapis.com / ajax / libs / jqueryui / 1.8 / jquery - ui.min.js "></script>
<meta http-equiv="
content - type " content="
text / html;
charset = utf - 8 "/>
<script type="
text / javascript " src="
https: //www.google.com/jsapi"></script>
< script type = "text/javascript"
src = "https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart','table','piechart','linechart','controls','charteditor']}]}" > < /script>
<script type="text/javascript">
var pieChartWrapper = null;
function pieChart() {
var pieJsonData = $.ajax({
url: "
http: //localhost:3000/test123",
dataType: "json",
async: false
}).responseText;
var pieData = new google.visualization.DataTable(pieJsonData);
var pieData = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
chartArea: {
left: 10,
top: 40,
height: 200,
width: 360
},
width: 300,
height: 260,
title: "Positive Contacts Percentage",
titleTextStyle: {
fontSize: 12
},
tooltip: {
showColorCode: true
},
legend: {
textStyle: {
fontSize: 10
},
position: 'left'
},
pieSliceTextStyle: {
fontSize: 10
}
}
var pieChartWrapper = new google.visualization.ChartWrapper({
chartType: 'PieChart',
containerId: 'pie_div',
dataTable: pieData,
options: options
});
google.visualization.events.addListener(pieChartWrapper, 'ready', selectHandler);
pieChartWrapper.draw();
}
function selectHandler(e) {
}
< /script>
</head > < body style = "font-size:62.5%;" > < form >
Start Date: < input type = "text"
name = "startdate"
id = "datepicker" / > End Date: < input type = "text"
name = "enddate"
id = "datepicker2" / >
< input type = "button"
value = "click me!"
onclick = "pieChart();" / >
< /form>
<div id="pie_div"></div >
< /body>
</html >
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 多个单选按钮组相互干扰
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- Javascript按钮下拉列表
- 如何使用按钮来调用在画布中绘制的函数
- 单击按钮时从输入框中绘制百分比条
- 在选择单选按钮时绘制窗体
- 点击谷歌可视化中的按钮后绘制图表
- 如何使用dataTablejquery将按钮一次性绘制到表中
- 单击按钮即可更新/重新绘制画布
- 单击按钮打开一个新窗口,并用D3绘制多个大圆
- 谷歌通过地理定位按钮绘制多个标记
- 使用单选按钮绘制圆形和方形不起作用
- 如何使用画布绘制圆角按钮
- 禁用单张绘制"删除"按钮
- 如何显示谷歌地图绘制工具时,按下按钮菜单
- Canvas KineticJS -点击按钮时重新绘制一些东西
- 使用AngularJS通过点击按钮绘制图形
- 单击按钮在画布上绘制图像不起作用