带有谷歌图表的JSP JSON - 折线图
JSP JSON with Google Charts - Line Charts
我的图表没有加载。我尝试使用 javascript 将 JSON 从 JSP 页面解析为 HTML 页面。
我不知道问题出在哪里。这是详细信息:
我的网页 :
<!DOCTYPE html>
<html>
<head>
<title>Google Chart with jsp Mysql Json</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var obj="";
google.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
url : 'getDataGlucose.jsp',
dataType:'json',
success : function(glucoseData) {
obj = JSON.stringify(glucoseData)
alert('Pass? : '+obj);
},
error : function(xhr, type) {
alert('server error occoured')
}
});
var google_data = {
"cols": [{
"type": "number"
}, {
"type": "number"
}],
rows: []
};
for (var i = 0; i < obj.length; i++) {
google_data.rows.push({
c: [{
v: obj[i].xValue
}, {
v: obj[i].glucose
}]
});
}
var data = new google.visualization.DataTable(google_data);
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
var options = {
title: 'Glucose Data Intake',
hAxis: {
title: 'Intake'
},
curveType: 'function',
vAxis: {
title: 'mmHg'
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
我从 JSP 页面生成 JSON:
[{"葡萄糖":5.5,"xValue":0}, {"葡萄糖":6.2,"xValue":1}, {"葡萄糖":5.8,"xValue":2}, {"葡萄糖":7,"xValue":3}, {"葡萄糖":6,"xValue":4}, {"葡萄糖":7.5,"xValue":5}, {"葡萄糖":6,"xValue":6}, {"葡萄糖":5.5,"xValue":7}, {"葡萄糖":6,"xValue":8}, {"葡萄糖":5.8,"xValue":9}]
找到了我的出路。我从 :
obj = JSON.stringify(glucoseData);
自
obj = eval('(' + JSON.stringify(glucoseData) + ')');
相关文章:
- 将对Ajax PUT的json响应重定向到要由EL解析的JSP中
- 使用jstl c:forEach在迭代jsp bean上创建javascript json对象
- 将数组从 Spring bean 转换为 JSON 以在 JSP 中引用
- 如何在jsp中的javascript函数中从servlet获取json返回
- 从jsp文件中读取带有javascript的json
- 使用 jquery 将 JSON 数组从 jsp 传递到 javascript
- 如何将Spring MVC的JSON响应放入jsp中的表中
- JSON 处理 - 向 JSP 发送 JSON 文本字符串,如何在 JSP 中处理
- 用 JSP 中的 JSON 填充 JSTree
- 如何在数据驱动文档中创建动态 json 并在 jsp 中获取 json 响应
- Struts2 到 ajax json 响应如何在 Jsp 页面上设置图像
- 带有谷歌图表的JSP JSON - 折线图
- 从 javascript 访问在 jsp 中创建的 JSON 字符串
- 如何将 JSON 对象从服务器发送到 JSP 并在 JSP 上接收响应
- 如何在 jsp 中显示 Json 来自 Restlet Server
- 将 Jackjson JSON 对象从 JSP 传递到 JavaScript 函数
- 如何将json数组从jsp传递到javascript
- 基本的JSP、JSON和AJAX实现
- 将JSON字符串从jsp传递到js文件
- 从servlet获取json响应并显示在jsp表中