年龄分布

This commit is contained in:
姚宇浩 2024-08-19 10:06:43 +08:00
parent 856b8a6930
commit 6a7d268a79
1 changed files with 76 additions and 20 deletions

View File

@ -33,12 +33,12 @@ const props = defineProps({
}, },
}); });
const data = reactive({ const data = reactive({
list: [709, 3424, 2064, 2980, ,], list: [],
unlist: [, , , 2980, 1790, 3100], unlist: [],
list2: [1548, 5895, 2753, 4602, ,], list2: [],
unlist2: [, , , 4602, 2030, 3900], unlist2: [],
list3: [180, 930, 632, 780, ,], list3: [],
unlist3: [, , , 780, 520, 600], unlist3: [],
year: [], year: [],
option: {}, option: {},
bg: [], bg: [],
@ -47,11 +47,30 @@ const data = reactive({
const chart = ref(); // DOM const chart = ref(); // DOM
const getOption = () => { const getOption = () => {
data.option = { data.option = {
// tooltip: { tooltip: {
// trigger: "axis", trigger: "axis",
// padding: [20, 10, 20, 10], padding: [20, 10, 20, 10],
// formatter: "{b0}:</br>{a0}:{c0}</br>{a1}:{c1}</br>{a2}:{c2}", formatter: function (params) {
// }, let result = "";
if (params[0].name <= data.year[2]) {
result = `${params[0].name}<br/>`;
} else {
result = `${params[0].name}预测数据<br/>`;
}
params.forEach(function (item, index) {
if (item.axisValue <= data.year[2]) {
if (index <= 2) {
result += `${item.seriesName}: ${item.value}<br/>`;
}
} else {
if (index > 2) {
result += `${item.seriesName}: ${item.value}<br/>`;
}
}
});
return result;
},
},
legend: { legend: {
data: ["0-18岁", "19-60岁", "60岁以上"], data: ["0-18岁", "19-60岁", "60岁以上"],
top: "3%", top: "3%",
@ -416,16 +435,56 @@ watch(
() => props.list, () => props.list,
(newValue, oldValue) => { (newValue, oldValue) => {
setTimeout(() => { setTimeout(() => {
// data.list = props.list; change()
// data.list2 = props.list2;
// data.list3 = props.list3;
data.year = props.year;
getOption(); getOption();
setChart(); setChart();
}, 600); }, 600);
} }
); );
const change = () => {
data.list.length=0;
data.list2.length=0;
data.list3.length=0;
data.unlist.length=0;
data.unlist2.length=0;
data.unlist3.length=0;
props.list.forEach((item, index) => {
if (index <= 2) {
data.list.push(item);
} else {
data.list.push("");
}
if (index >= 2) {
data.unlist.push(item);
} else {
data.unlist.push("");
}
});
props.list2.forEach((item, index) => {
if (index <= 2) {
data.list2.push(item);
} else {
data.list2.push("");
}
if (index >= 2) {
data.unlist2.push(item);
} else {
data.unlist2.push("");
}
});
props.list3.forEach((item, index) => {
if (index <= 2) {
data.list3.push(item);
} else {
data.list3.push("");
}
if (index >= 2) {
data.unlist3.push(item);
} else {
data.unlist3.push("");
}
});
};
const setChart = () => { const setChart = () => {
// Vue3 // Vue3
var myChart = echarts.init(chart.value); var myChart = echarts.init(chart.value);
@ -433,12 +492,9 @@ const setChart = () => {
// 使 // 使
myChart.setOption(data.option); myChart.setOption(data.option);
}; };
onBeforeMount(() => { onBeforeMount(() => {
setTimeout(() => { setTimeout(() => {
// data.list = props.list; change();
// data.list2 = props.list2;
// data.list3 = props.list3;
data.year = props.year; data.year = props.year;
getOption(); getOption();
setChart(); setChart();