1.图表控件
<div id="main" style="width: 600px;height:400px;"></div>
2.js
引入
var echarts = require('echarts');
//自动请求
cumpute(){
var params = {
canshu: this.radio
};
//发送异步请求
cumputes(params).then(function(result){
alert(result.data.chart);
this.chart=result.data.chart;
//调用方法
this.drawchart();
}.bind(this)).catch(function (error) {
this.loading2 = false;
console.log(error);
}.bind(this));
},
drawchart(){
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '第一个 ECharts 实例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: this.chart
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
},
3.后台
@GetMapping("/cumputes")
public ResponseData jisuan (String canshu) {
//调用python
int[] chart=new int[] {5, 20, 36, 10, 10, 55};
Map<String, Object> result = new HashMap ();
result.put("chart",chart);
return ResponseData.ok(result);
}