/** * 顶部header */ Vue.component("trend-line-chart", { template: `
`, props: { chartdata:{ type:Object }, height:{ type:Number }, data:{ type:Array } }, data() { return { option:{} } }, mounted(){ this.init() }, methods: { init(){ this.getChartData() }, getChartData(){ //品类金额占比 饼图 var myChart = echarts.init(this.$refs.chart); this.echartPie(myChart,this.chartdata) }, echartPie(myChart,data){ let newPromise = new Promise((resolve) => { resolve() }) //然后异步执行echarts的初始化函数 newPromise.then(() => { var series =[] for (let i = 0; i < data.data.length; i++) { series.push({ name:data.legend[i], type: "line", smooth: true, symbol: "circle", symbolSize: 5, showSymbol: true, lineStyle: { normal: { width: 2, }, }, data: data.data[i], }) } var unit = '' if(data.unit){ unit = '单位:'+data.unit } this.option = { color : data.color, tooltip: { trigger: "axis", axisPointer: { lineStyle: { color: "#57617B", }, }, }, grid: { top:'15%', left: "30", right: "3%", bottom: "1%", containLabel: true, }, xAxis: { type: "category", boundaryGap: false, data: data.dataX, axisLine: { //坐标轴轴线相关设置。数学上的x轴 show: true, lineStyle: { color: "#25597e", type: "dashed", }, }, axisTick: { show: false }, axisLabel: { //坐标轴刻度标签的相关设置 textStyle: { color: "#c5d9fc", margin: 20, fontSize:16 }, }, }, yAxis: { name:unit, nameTextStyle: { color: '#fff', fontSize: 14, }, type: "value", axisLine: { //坐标轴轴线相关设置。数学上的x轴 show: false, lineStyle: { color: "#c5d9fc", type: "dashed", }, }, axisTick: { show: false }, axisLabel: { show: true, //坐标轴刻度标签的相关设置 textStyle: { color: "#c5d9fc", margin: 20, fontSize:16 }, }, splitLine: { show: true, lineStyle: { color: "#25597e", type: "dashed", }, }, }, series: series }; myChart.setOption(this.option,true); window.onresize = myChart.resize; }) }, }, watch:{ /*chartdata: { deep:true, handler: function (val, oldVal){ this.init() } },*/ data: function (val, oldVal){ this.init() } } })