ggfwjsc/src/view/echarts_education/pie.vue

189 lines
3.8 KiB
Vue
Raw Normal View History

2024-04-17 15:25:43 +08:00
<template>
2024-04-17 16:53:36 +08:00
<div
ref="chart"
2024-04-18 11:52:01 +08:00
style="width: 50%;height: 280px"
2024-04-17 16:53:36 +08:00
></div>
2024-04-17 15:25:43 +08:00
</template>
2024-04-17 16:53:36 +08:00
<script setup>
2024-04-17 15:25:43 +08:00
import { onMounted, reactive, ref } from "vue";
// 局部引入echarts核心模块
import * as echarts from "echarts";
const chart = ref(); // 创建DOM引用
let option = {
tooltip: {
trigger: "axis",
2024-04-17 16:53:36 +08:00
formatter: "{b0}<br />{a0}:{c0} <br />{a1}:{c1}<br />{a2}:{c2} ",
2024-04-17 15:25:43 +08:00
},
legend: {
top: "8%",
right: "11%",
textStyle: {
fontSize: 12,
color: "#ccc",
},
},
grid: {
left: "1%",
right: "10%",
bottom: "0%",
containLabel: true,
},
calculable: true,
xAxis: [
{
type: "category",
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ccc",
},
},
2024-04-17 16:53:36 +08:00
axisTick: {
show: false, // 设置轴刻度不显示
},
data: ["小学", "初中", "高中"],
2024-04-17 15:25:43 +08:00
},
{
axisTick: false,
type: "category",
2024-04-17 16:53:36 +08:00
data: ["小学", "初中", "高中"],
2024-04-17 15:25:43 +08:00
axisLabel: {
show: false,
},
},
],
yAxis: [
{
type: "value",
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ccc",
},
},
},
{
type: "value",
min: 0,
max: 100,
splitLine: {
show: false,
lineStyle: {
type: "solid",
color: "rgb(221, 242, 255,0.1)",
},
},
axisLine: {
show: false,
lineStyle: {
type: "dotted",
},
},
axisLabel: {
show: false,
fontSize: 14,
fontFamily: "MicrosoftYaHei",
color: "#DEF1FF",
lineHeight: 19,
},
},
],
series: [
{
name: "城市",
type: "bar",
2024-04-17 16:53:36 +08:00
data: [2.0, 4.9, 7.0],
2024-04-17 15:25:43 +08:00
barWidth: "18%",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "rgba(142, 187, 255, 1)",
},
{
offset: 1,
color: "rgba(142, 187, 255, 0.20)",
},
]),
},
},
{
name: "县镇",
type: "bar",
2024-04-17 16:53:36 +08:00
data: [2.6, 5.9, 9.0],
2024-04-17 15:25:43 +08:00
barWidth: "18%",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "rgba(23, 136, 255, 1)",
},
{
offset: 1,
color: "rgba(23, 136, 255, 0.20)",
},
]),
},
},
{
name: "农村",
type: "bar",
2024-04-17 16:53:36 +08:00
data: [2.6, 5.9, 9.0],
2024-04-17 15:25:43 +08:00
barWidth: "18%",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "rgba(23, 237, 255, 1)",
},
{
offset: 1,
color: "rgba(23, 237, 255, 0.20)",
},
]),
},
},
{
type: "bar",
xAxisIndex: 1,
yAxisIndex: 1,
itemStyle: {
color: "rgba(221, 242, 255, 0.1)",
},
2024-04-17 16:53:36 +08:00
data: ["2019", "2020", "2021"].map(() => 100),
2024-04-18 14:52:27 +08:00
barWidth: 70,
2024-04-17 15:25:43 +08:00
},
],
};
// 使用生命钩子
onMounted(() => {
// 基于准备好的dom初始化echarts实例
// var myChart = echarts.init(document.getElementById('main'));
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// init(); // vue3.2没有this
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
// 单图表响应式: 跟随浏览器大小改变
// window.addEventListener("resize", () => {
// myChart.resize();
// });
});
</script>
2024-04-17 16:53:36 +08:00
<style scoped></style>