1、在api/sta.js中创建接口方法
showData(searchObj){
return request({
url: `/staservice/stadaily/showData/${searchObj.type}/${searchObj.begin}/${searchObj.end}`,
method: 'get'
})
}
2 、改造daily/show.vue页面js方法
<script>
import echarts from "echarts";
import sta from "@/api/sta";
export default {
data() {
return {
searchObj: {},
btnDisabled: false,
xData: [],
yData: []
};
},
created() {},
methods: {
showChart() {
sta.showData(this.searchObj).then(response => {
this.xData = response.data.dateCalculatedList;
this.yData = response.data.dataList;
this.setCharts();
});
},
setCharts() {
var myChart = echarts.init(document.getElementById("chart"));
var option = {
xAxis: {
type: "category",
data: this.xData
},
yAxis: {
type: "value"
},
series: [
{
data: this.yData,
type: "line"
}
],
dataZoom: [
{
show: true,
height: 30,
xAxisIndex: [0],
bottom: 30,
start: 10,
end: 80,
handleIcon:
"path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
handleSize: "110%",
handleStyle: {
color: "#d3dee5"
},
textStyle: {
color: "#fff"
},
borderColor: "#90979c"
},
{
type: "inside",
show: true,
height: 15,
start: 1,
end: 35
}
]
};
myChart.setOption(option);
}
}
};
</script>