|
|
@@ -51,6 +51,7 @@ |
|
|
|
|
|
|
|
<script setup lang="ts" name="home"> |
|
|
|
import * as echarts from "echarts"; |
|
|
|
import { portraitSummaryApi } from "@/api"; |
|
|
|
const chart1 = ref(null); |
|
|
|
const chart2 = ref(null); |
|
|
|
const chart4 = ref(null); |
|
|
@@ -58,15 +59,35 @@ const chart5 = ref(null); |
|
|
|
onMounted(() => { |
|
|
|
getDataChart(); |
|
|
|
}); |
|
|
|
function getDataChart() { |
|
|
|
getCharts1(); |
|
|
|
getCharts2(); |
|
|
|
getCharts4(); |
|
|
|
getCharts5(); |
|
|
|
} |
|
|
|
const getDataChart = async () => { |
|
|
|
/* 获取学生性别 */ |
|
|
|
let sex: any = await portraitSummaryApi.getStudentSex(); |
|
|
|
getCharts1(sex.data.label, sex.data.value); |
|
|
|
/* 获取学生年龄 */ |
|
|
|
let age: any = await portraitSummaryApi.getStudentAge(); |
|
|
|
getCharts2(age.data.label, age.data.value); |
|
|
|
/* 获取属性标签 */ |
|
|
|
let attr: any = await portraitSummaryApi.getStudentAttr(); |
|
|
|
getCharts4(attr.data.label, attr.data.value); |
|
|
|
/* 获取地理位置 */ |
|
|
|
let address: any = await portraitSummaryApi.getAddress(); |
|
|
|
getCharts5(address.data.label, address.data.value); |
|
|
|
}; |
|
|
|
|
|
|
|
const handleDate = (label: any, value: any, key: any = "") => { |
|
|
|
let data: any = []; |
|
|
|
label.forEach((item: any, index: number) => { |
|
|
|
data.push({ |
|
|
|
value: value[index], |
|
|
|
name: item + key |
|
|
|
}); |
|
|
|
}); |
|
|
|
return data; |
|
|
|
}; |
|
|
|
/* 性別 */ |
|
|
|
function getCharts1() { |
|
|
|
function getCharts1(label: any, value: any) { |
|
|
|
const chart = echarts.init(chart1.value); |
|
|
|
const data = handleDate(label, value); |
|
|
|
const option = { |
|
|
|
tooltip: { |
|
|
|
confine: true |
|
|
@@ -76,7 +97,7 @@ function getCharts1() { |
|
|
|
right: "0%", |
|
|
|
top: "center", |
|
|
|
orient: "vertical", |
|
|
|
data: ["男", "女"] |
|
|
|
data: label |
|
|
|
}, |
|
|
|
series: [ |
|
|
|
{ |
|
|
@@ -104,16 +125,7 @@ function getCharts1() { |
|
|
|
show: true |
|
|
|
} |
|
|
|
}, |
|
|
|
data: [ |
|
|
|
{ |
|
|
|
value: 62, |
|
|
|
name: "男" |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: 100, |
|
|
|
name: "女" |
|
|
|
} |
|
|
|
] |
|
|
|
data: data |
|
|
|
} |
|
|
|
] |
|
|
|
}; |
|
|
@@ -124,15 +136,18 @@ function getCharts1() { |
|
|
|
}); |
|
|
|
} |
|
|
|
/* 年齡 */ |
|
|
|
function getCharts2() { |
|
|
|
function getCharts2(label: any, value: any) { |
|
|
|
const chartstation = echarts.init(chart2.value); |
|
|
|
const data = handleDate(label, value, "岁"); |
|
|
|
const labelArr: any = []; |
|
|
|
label.map((item: any) => labelArr.push(item + "岁")); |
|
|
|
const option = { |
|
|
|
legend: { |
|
|
|
show: true, |
|
|
|
right: "0%", |
|
|
|
top: "center", |
|
|
|
orient: "vertical", |
|
|
|
data: ["<20", ">60岁", "50-60岁", "40-50岁", "30-40岁", "20-30岁"] |
|
|
|
data: labelArr |
|
|
|
}, |
|
|
|
tooltip: { |
|
|
|
trigger: "item", |
|
|
@@ -146,32 +161,7 @@ function getCharts2() { |
|
|
|
radius: [50, 140], |
|
|
|
|
|
|
|
roseType: "area", |
|
|
|
data: [ |
|
|
|
{ |
|
|
|
value: 10, |
|
|
|
name: "<20" |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: 15, |
|
|
|
name: ">60岁" |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: 25, |
|
|
|
name: "50-60岁" |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: 20, |
|
|
|
name: "40-50岁" |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: 35, |
|
|
|
name: "30-40岁" |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: 30, |
|
|
|
name: "20-30岁" |
|
|
|
} |
|
|
|
], |
|
|
|
data: data, |
|
|
|
itemStyle: { |
|
|
|
normal: { |
|
|
|
label: { |
|
|
@@ -194,17 +184,19 @@ function getCharts2() { |
|
|
|
}); |
|
|
|
} |
|
|
|
/* 兴趣爱好 */ |
|
|
|
function getCharts4() { |
|
|
|
function getCharts4(categoryData: any, dataArr: any) { |
|
|
|
const chartstation = echarts.init(chart4.value); |
|
|
|
var dataArr = [100, 200, 300, 400, 500]; |
|
|
|
var spaceLength = 5, |
|
|
|
fixedData = [], |
|
|
|
end = 0, |
|
|
|
max = 300; |
|
|
|
// var categoryData = ys.超市品牌; |
|
|
|
var categoryData = ["调皮/爱打闹", "上课不认真听讲", "爱好运动", "爱好画画", "爱好学习"]; |
|
|
|
var xhao = [1, 2, 3, 4, 5]; |
|
|
|
var data1 = dataArr.map(item => { |
|
|
|
let xhao: any = []; |
|
|
|
for (var i = 0; i < dataArr.length; i++) { |
|
|
|
xhao.push(i + 1); |
|
|
|
} |
|
|
|
|
|
|
|
var data1 = dataArr.map((item: any) => { |
|
|
|
fixedData.push(spaceLength); |
|
|
|
return item - spaceLength; |
|
|
|
}); |
|
|
@@ -399,11 +391,9 @@ function getCharts4() { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/* 标签 */ |
|
|
|
function getCharts5() { |
|
|
|
/* 标签、地理位置 */ |
|
|
|
function getCharts5(nameArr: any, valueArr: any) { |
|
|
|
const chartstation5 = echarts.init(chart5.value); |
|
|
|
const nameArr = ["杭州", "宁波", "金华", "台州", "嘉兴", "丽水", "温州", "潮州", "绍兴", "衢州"]; |
|
|
|
const valueArr = [150, 60, 80, 180, 120, 160, 80, 40, 20, 10]; |
|
|
|
const option = { |
|
|
|
grid: { |
|
|
|
top: "10%", |
|
|
@@ -449,7 +439,7 @@ function getCharts5() { |
|
|
|
}, |
|
|
|
axisLabel: { |
|
|
|
textStyle: { |
|
|
|
color: "#B3CFFF", // x轴文本颜色 |
|
|
|
color: "#333", // x轴文本颜色 |
|
|
|
fontSize: 12 |
|
|
|
} |
|
|
|
// rotate:30, |
|
|
@@ -471,7 +461,7 @@ function getCharts5() { |
|
|
|
axisLabel: { |
|
|
|
formatter: "{value}", |
|
|
|
textStyle: { |
|
|
|
color: "#B3CFFF", // x轴文本颜色 |
|
|
|
color: "#333", // x轴文本颜色 |
|
|
|
fontSize: 12 |
|
|
|
} |
|
|
|
}, |
|
|
@@ -489,6 +479,19 @@ function getCharts5() { |
|
|
|
emphasis: { |
|
|
|
itemStyle: { |
|
|
|
color: "#7fb7e9" |
|
|
|
}, |
|
|
|
label: { |
|
|
|
textStyle: { |
|
|
|
color: "#7fb7e9" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
label: { |
|
|
|
show: true, |
|
|
|
position: "top", |
|
|
|
textStyle: { |
|
|
|
color: "rgba(147, 157, 223, 1)", |
|
|
|
padding: [0, 10] |
|
|
|
} |
|
|
|
}, |
|
|
|
itemStyle: { |
|
|
|