ggfwjsc/src/view/echarts_hygiene/pie3_1.vue

175 lines
3.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div ref="chart" style="width: 100%; height: 280px"></div>
</template>
<script setup >
import { onMounted, reactive, ref, onBeforeMount, defineProps } from "vue";
// 局部引入echarts核心模块
import * as echarts from "echarts";
const props = defineProps({
list: {
type: Array,
default: () => [],
},
year: {
type: Array,
default: () => [],
},
});
const chart = ref(); // 创建DOM引用
const data = reactive({
list1: [4167.703845,4736.436645, 5345.882021, 5761.09324, 7615.018745],
list2: [4160.310608,5668.346418, 6463.614862, 7169.546084, 9450.380778],
year: [2019,2020, 2021, 2022, 2023],
bg: [0, 0, 0, 0,0],
option: {},
});
const getOption = () => {
data.option = {
tooltip: {
trigger: "axis",
padding: [20, 10, 20, 10],
formatter: "{b0}<br />{a0}:{c0}万元<br />{a1}:{c1}万元 ",
},
legend: {
data: ["职工", "城乡"],
top: "6%",
right: "5%",
textStyle: {
fontSize: 16,
color: "#ffffff",
},
},
grid: {
top: "20%",
left: "1%",
right: "10%",
bottom: "3%",
containLabel: true,
},
xAxis: {
type: "category",
// boundaryGap: false,
data: data.year,
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
fontSize: 16,
},
},
},
yAxis: {
name: "金额/万元",
type: "value",
nameTextStyle: {
// 设置Y轴名称的样式
fontSize: 14, // 这里设置字体大小为20
},
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
fontSize: 16,
},
},
axisLine: {
//y轴线的颜色以及宽度
show: false,
lineStyle: {
color: "#ffffff",
fontSize: 16,
width: 1,
type: "solid",
},
},
},
series: [
{
name: "职工",
type: "line",
stack: "Total",
symbol: "emptyCircle",
smooth: true,
symbolSize: 10,
label: {
show: true,
color: "#ffffff",
position: "top",
fontSize: 14,
formatter: function (data) {
return data.value.toFixed(0);
},
},
itemStyle: {
borderColor: "#00FCFF",
borderWidth: 1,
color: "#00FCFF",
},
data: data.list1,
},
{
name: "城乡",
type: "line",
stack: "Total",
symbol: "emptyCircle",
smooth: true,
symbolSize: 10,
label: {
show: true,
color: "#ffffff",
position: "top",
fontSize: 14,
formatter: function (data) {
return data.value.toFixed(0);
},
},
itemStyle: {
borderColor: "#2468FF",
borderWidth: 1,
color: "#2468FF",
},
data: data.list2,
},
{
name: "背景",
type: "bar",
data: data.bg,
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
],
};
};
const setChart = () => {
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(data.option);
};
onBeforeMount(() => {
setTimeout(() => {
// data.list = props.list;
// data.year = props.year;
getOption();
setChart();
}, 600);
});
</script>
<style scoped>
</style>