用Echats画表,已经将Mysql的数据成功读到了web上,可是 $.ajax请求不成功
success: function(res)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="../static/js/echarts.min.js"></script>
<script src="../static/js/jquery.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('main'));
// 定义x、y轴数据数组
var names=[];
var nums=[];
//请求后台数据
$.ajax({
type: "get",
url: "http://localhost:8080/goods/list",
contentType: "application/list;charset=utf-8",
success: function(res){
console.log("=====res: =======")
console.log(res);
for (var i = 0; i < res.length ; i++) {
names.push(res[i].visittime);
nums.push(res[i].num);
}
myChart.setOption({
xAxis: {
data: names
},
series: [{
// 根据名字对应到相应的系列
name: '点击量',
type: 'bar',
data: nums
}]
});
},
error: function(res){
alert("图表请求数据失败!");
myChart.hideLoading()
}
});
</script>
</body>
</html>