可以在mounted方法中调用getuserstudy方法,获取leavetime的值,并将其赋值给pieOptionStudy中的data数组中的第二个对象的value属性,代码如下:

mounted() { this.getuserstudy(); const pieChart1Dom = this.$refs.pieChart1; const pieChart2Dom = this.$refs.pieChart2; const pieChart1Instance = echarts.init(pieChart1Dom); const pieChart2Instance = echarts.init(pieChart2Dom); const pieOptionStudy = { title: { text: '学习时长', x: 'center' }, tooltip: { trigger: 'item', formatter: '{a}
{b}: {c} ({d}%)' }, legend: { orient: 'vertical', left: 10, data: ['学习时长', '中途离开时长 '] }, series: [ { name: '任务完成情况', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } }, labelLine: { show: false }, data: [ {value: 1, name: '学习时长'}, {value: this.leavetime, name: '中途离开时长'} ] } ] }; const pieOptionTask = { title: { text: '任务完成情况', x: 'center' }, tooltip: { trigger: 'item', formatter: '{a}
{b}: {c} ({d}%)' }, legend: { orient: 'vertical', left: 10, data: ['已完成', '未完成'] }, series: [ { name: '任务完成情况', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } }, labelLine: { show: false }, data: [ {value: 16, name: '已完成'}, {value: 4, name: '未完成'} ] } ] }; pieChart1Instance.setOption(pieOptionStudy); pieChart2Instance.setOption(pieOptionTask); }, methods:{ getuserstudy(){ this.$net.get('/task/notfinish').then(resp => { this.studytime=resp.data.data[0] this.leavetime=resp.data.data[1] this.finishtask=resp.data.data[2] this.underfinishtask=resp.data.data[3] // 将leavetime的值赋给pieOptionStudy中的data数组中的第二个对象的value属性 pieOptionStudy.series[0].data[1].value = this.leavetime; }); } }


原文地址: https://www.cveoy.top/t/topic/bdnS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录