4 changed files with 130 additions and 93 deletions
@ -1,113 +1,144 @@ |
|||||
<template> |
<template> |
||||
<div id="barEcharts" style="width:380px;height:350px"></div> |
<div id="barEcharts" style="width: 380px; height: 350px"></div> |
||||
</template> |
</template> |
||||
<script setup> |
<script setup> |
||||
import{onMounted} from 'vue'; |
import { onMounted } from 'vue'; |
||||
|
import { timeFinancialChart } from 'apis/projectFinance'; |
||||
|
|
||||
onMounted(()=>{ |
const projectId = useProjectId(); |
||||
const myChart = echarts.init(document.getElementById('barEcharts')); |
|
||||
const option = { |
|
||||
tooltip: { |
|
||||
trigger: 'axis', |
|
||||
axisPointer: { |
|
||||
type: 'shadow', |
|
||||
}, |
|
||||
}, |
|
||||
legend: { |
|
||||
top:10, |
|
||||
right:0, |
|
||||
icon: 'circle', |
|
||||
orient: 'horizontal', |
|
||||
itemGap: 10, |
|
||||
itemWidth: 10, |
|
||||
itemHeight: 14, |
|
||||
textStyle: { |
|
||||
fontSize: 14, |
|
||||
color: '#858585', |
|
||||
fontWeight: 400, |
|
||||
}, |
|
||||
|
|
||||
}, |
const data = reactive({ |
||||
data: ['任务一', '任务二', '任务三', '任务四'], |
timeList: [], |
||||
color: ['#7E84A3', '#FF914C', '#5189F8', '#3FC7BB'], |
taskNameList: [], |
||||
grid: { |
}); |
||||
left: '10%', |
|
||||
right: '0', |
async function getChartData() { |
||||
bottom: '5%', |
try { |
||||
containLabel: false, |
const params = { param: { projectId: projectId.value } }; |
||||
}, |
const res = await timeFinancialChart(params); |
||||
xAxis: { |
console.log('res:', res); |
||||
type: 'category', |
return processing(res); |
||||
data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'], |
} catch (error) { |
||||
axisTick: { |
console.error(error); |
||||
show: false, |
} |
||||
}, |
} |
||||
axisLabel: { |
|
||||
show: true, |
function processing(list) { |
||||
}, |
let timeList = [ |
||||
axisLine: { |
null, |
||||
show: false, |
null, |
||||
}, |
null, |
||||
}, |
null, |
||||
yAxis: { |
null, |
||||
type: 'value', |
null, |
||||
splitLine: { |
null, |
||||
lineStyle: { |
null, |
||||
color: '#F3F4F5', |
null, |
||||
}, |
null, |
||||
}, |
null, |
||||
}, |
null, |
||||
series: [ |
]; |
||||
{ |
for (let i = 0; i < list.length; i++) { |
||||
name: '任务四', |
for (let j = 0; j < list[i].data.length; j++) { |
||||
|
const m = list[i].data[j].time - 0; |
||||
|
timeList[m - 1] = m + '月'; |
||||
|
} |
||||
|
} |
||||
|
for (let i = 0; i < timeList.length; i++) { |
||||
|
if (!timeList[i]) { |
||||
|
timeList.splice(i, 1); |
||||
|
i -= 1; |
||||
|
} |
||||
|
} |
||||
|
let series = []; |
||||
|
let taskNameList = []; |
||||
|
for (let i = 0; i < list.length; i++) { |
||||
|
let data = []; |
||||
|
taskNameList.push(list[i].name); |
||||
|
for (let k = 0; k < timeList.length; k++) { |
||||
|
data.push(null); |
||||
|
} |
||||
|
for (let k = 0; k < list[i].data.length; k++) { |
||||
|
for (let m = 0; m < timeList.length; m++) { |
||||
|
if (list[i].data[k].time - 0 + '月' === timeList[m]) { |
||||
|
data[m] = list[i].data[k].expend - 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
let obj = { |
||||
|
name: list[i].name, |
||||
type: 'bar', |
type: 'bar', |
||||
stack: 'total', |
stack: 'total', |
||||
label: { |
label: { |
||||
show: false, |
show: false, |
||||
color: '#FFFFFF', |
color: '#FFFFFF', |
||||
}, |
}, |
||||
itemStyle: { |
|
||||
borderRadius: [0, 0, 0, 0], |
|
||||
}, |
|
||||
barWidth: 12, |
barWidth: 12, |
||||
data: [320, 80, 301, 334, 390, 330, 320, 390, 330, 320, 390, 390], |
data: data, |
||||
|
}; |
||||
|
series.push(obj); |
||||
|
} |
||||
|
data.timeList = timeList; |
||||
|
data.taskNameList = taskNameList; |
||||
|
console.log('series: ', series); |
||||
|
return series; |
||||
|
} |
||||
|
|
||||
|
onMounted(async () => { |
||||
|
const myChart = echarts.init(document.getElementById('barEcharts')); |
||||
|
const series = await getChartData(); |
||||
|
const option = { |
||||
|
tooltip: { |
||||
|
trigger: 'axis', |
||||
|
axisPointer: { |
||||
|
type: 'shadow', |
||||
|
}, |
||||
}, |
}, |
||||
{ |
legend: { |
||||
name: '任务三', |
top: 10, |
||||
type: 'bar', |
right: 0, |
||||
stack: 'total', |
icon: 'circle', |
||||
label: { |
orient: 'horizontal', |
||||
show: false, |
itemGap: 10, |
||||
color: '#FFFFFF', |
itemWidth: 10, |
||||
|
itemHeight: 14, |
||||
|
textStyle: { |
||||
|
fontSize: 14, |
||||
|
color: '#858585', |
||||
|
fontWeight: 400, |
||||
}, |
}, |
||||
data: [120, 132, 101, 134, 90, 230, 210, 302, 301, 334, 390, 330], |
|
||||
}, |
}, |
||||
{ |
data: data.taskNameList, |
||||
name: '任务二', |
color: ['#7E84A3', '#FF914C', '#5189F8', '#3FC7BB'], |
||||
type: 'bar', |
grid: { |
||||
stack: 'total', |
left: '15%', |
||||
label: { |
right: '0', |
||||
|
bottom: '5%', |
||||
|
containLabel: false, |
||||
|
}, |
||||
|
xAxis: { |
||||
|
type: 'category', |
||||
|
data: data.timeList, |
||||
|
axisTick: { |
||||
show: false, |
show: false, |
||||
color: '#FFFFFF', |
|
||||
}, |
}, |
||||
data: [18, 66, 191, 234, 290, 330, 310, 182, 191, 234, 290, 330], |
axisLabel: { |
||||
}, |
show: true, |
||||
{ |
}, |
||||
name: '任务一', |
axisLine: { |
||||
type: 'bar', |
|
||||
stack: 'total', |
|
||||
label: { |
|
||||
show: false, |
show: false, |
||||
color: '#FFFFFF', |
|
||||
}, |
}, |
||||
itemStyle: { |
}, |
||||
borderRadius: [0, 0, 0, 0], |
yAxis: { |
||||
|
type: 'value', |
||||
|
splitLine: { |
||||
|
lineStyle: { |
||||
|
color: '#F3F4F5', |
||||
|
}, |
||||
}, |
}, |
||||
data: [150, 212, 201, 154, 190, 330, 410, 182, 191, 234, 290, 330], |
|
||||
}, |
}, |
||||
], |
series: series, |
||||
}; |
}; |
||||
|
|
||||
myChart.setOption(option); |
myChart.setOption(option); |
||||
}) |
}); |
||||
</script> |
</script> |
||||
|
Loading…
Reference in new issue