forked from pengzhongghost/test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecharts.java
More file actions
89 lines (86 loc) · 3.03 KB
/
echarts.java
File metadata and controls
89 lines (86 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
1.前台代码:
<script type="text/javascript">
$(function () {
$.post("/EchartsController/showEcharts",{},function (data) {
var names=[];
var list1 = data["incomes"];
for (var i=0;i<list1.length;i++){
names.push(list1[i].name);
}
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('container'));
// 指定图表的配置项和数据
var option = {
title: {
text: '某站点用户访问来源',
subtext: '纯属虚构',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: names,
},
series: [
{
name: '访问来源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data:list1,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
})
})
</script>
2.后台代码
@Controller
@RequestMapping("/EchartsController")
public class EchartsController {
@Autowired
IncomeService incomeService;
@RequestMapping("/showEcharts")
@ResponseBody
public Object showEcharts(){
List<IncomeDetails> incomes=incomeService.selectAll();
HashMap<String,List> hashMap=new HashMap<>();
hashMap.put("incomes",incomes);
return hashMap;
}
}
public class IncomeDetails {
private String name;
private Double value;
public IncomeDetails() {
}
public IncomeDetails(String name, Double value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getValue() {
return value;
}
public void setValue(Double value) {
this.value = value;
}
}