动态获取后台数据(list类型)的那种--终于会啦~~~~~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="/js/echarts.min.js"></script>
<script src="/js/jquery-3.1.1.js"></script>
<script src="/js/china.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
//定义x轴、y轴数据
var names=[];
var counts=[];
var series1=[];
//请求后台数据
$.ajax({
type:"get",
url:"/student/getList",
contentType:"application/json",
success:function (res){
var size=res.length;
console.log(size);
// console.log(all);
// console.log("======log======")
// console.log(res);
var mapdata=[];
for(var i=0;i<res.length;i++){
names.push(res[i].name);
counts.push(res[i].count);
mapdata.push({name:names[i],value:counts[i]});
// alert(names[i]+" "+counts[i]);
}
myChart.setOption({
xAxis: {
data:names,
axisLabel: {
interval:0
}
},
series: [{
name:"人数",
data:mapdata
}]
})
}
})
// 指定图表的配置项和数据
var option = {
title: {
text: '动态获取数据库数据'
},
tooltip: {},
legend: {
data:['数量']
},
xAxis: {
data: []
},
yAxis: {},
series: [{
name: '数量',
type: 'map',
mapType:'china',
data: []
}]
};
series1=[];
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
</body>
</html>
标签:console,log,--,res,json,var,echarts
From: https://www.cnblogs.com/liuzijin/p/17760894.html