为了账号安全,请及时绑定邮箱和手机立即绑定

通过AJAX请求根据用户输入重绘Google图表

通过AJAX请求根据用户输入重绘Google图表

PHP
炎炎设计 2019-07-25 15:00:35
通过AJAX请求根据用户输入重绘Google图表我有一个谷歌图表从我的数据库中提取数据,这是我想要的。根据URL中的get请求,它从选定的表中绘制数据。我想根据下拉菜单中的选定表格通过ajax更新此图表。我无法突破的部分是通过ajax响应数据。我认为下面的代码是接近的,但我得到了以下错误,我似乎无法摆脱。getdata.php:22未捕获的ReferenceError:$未定义drawVisualization @ getdata.php:22onchange @ getdata.php:47我尝试从getdata.php中删除GET请求并硬编码一个表,认为这是$ not defined,但是没有解决错误。工作图代码<!DOCTYPE><html><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Wind Graph</title><script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load('visualization', '1', {packages: ['corechart']});</script><script type="text/javascript">function drawVisualization() {var data = new google.visualization.DataTable();<?phprequire("dbconnect.php");echo " data.addColumn('string', 'Time');";echo " data.addColumn('number', 'Wind_Speed');";echo " data.addColumn('number', 'Wind_Gust');";$db = mysql_connect($server, $user_name, $password);mysql_select_db($database);$sqlQuery = "SELECT * FROM ".$_GET['q']." WHERE Date(Time + INTERVAL 10 HOUR) = Date(UTC_TIMESTAMP() + INTERVAL 10 HOUR)";$sqlResult = mysql_query($sqlQuery);while ($row = mysql_fetch_assoc($sqlResult)) {echo " data.addRow(['{$row['Time']}', {v: {$row['Wind_Speed']}, f: '{$row['Wind_Speed']}' }, {v: {$row['Wind_Gust']}, f: '{$row['Wind_Gust']}' } ]); ";}?>// Create and draw the visualization.new google.visualization.LineChart(document.getElementById('visualization')).draw(data, {curveType: "none",title: "AU0001 Wind Chart",titleTextStyle: {color: "orange"},//width: 800, height: 400,//vAxis: {maxValue: 10},vAxis: {minValue: 0},vAxis: {title: 'Wind Speed (Knots)'},vAxis: {baseline: 0},vAxis: {gridlines: {count: 10}  },vAxis: {title: "Wind Speed (Knots)", titleTextStyle: {color: "orange"}},hAxis: {title: "Time", titleTextStyle: {color: "orange"}},interpolateNulls: 1});}google.setOnLoadCallback(drawVisualization);</script></head><body><div id="visualization" style="width: 100%; height: 400px;"></div></body></html>
查看完整描述

2 回答

?
扬帆大鱼

TA贡献1799条经验 获得超9个赞

我在html文件的页面加载时得到以下错误:graphindexnew1.php:14未捕获的ReferenceError:$未定义回调@ graphindexnew1.php:14它指向这行代码$("#users").change(drawChart);

查看完整回答
反对 回复 2019-07-25
  • 2 回答
  • 0 关注
  • 419 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信