惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
I
InfoQ
宝玉的分享
宝玉的分享
G
Google Developers Blog
J
Java Code Geeks
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
腾讯CDC
F
Fortinet All Blogs
A
About on SuperTechFans
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
B
Blog RSS Feed
博客园 - 聂微东
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
L
LangChain Blog
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏

博客园 - zhaogaojian

Qt 5 界面闪烁与白屏问题的原因及解决办法 开发的一款IOTLink,物联网调试工具集 禁用嵌入式设备自动命名usb网卡成enxXXXXX 关闭vEthernet (Default Switch) windows设备2通过linux设备1上网 windows下的/data目录 VSCode创建launch.json的作用 Linux启动时候Ip有时候不显示问题 Android Release模式下无法运行一例解决方法 修改了命名空间后ActivityMainBinding使用爆红 Android MPAndroidChart设置折线点为横轴+纵轴数据 Android停止蓝牙扫描不起作用 MiniCom打开回显 一例ssh无法连接问题 一例串口输出异常问题 Ubuntu14.04 设置共享文件夹 2、el-image设置error图像 1、自定义上传组件实现动态指定action Android 手机生成文件电脑上看不见 Android 一例Base64错误问题
3、使用ECharts控件
zhaogaojian · 2023-12-07 · via 博客园 - zhaogaojian

这个示例使用了 ECharts 的饼图,并使用了 Vue.js 的生命周期钩子函数 mounted 来在组件挂载后初始化图表。在 data 中,chartData 存储了图表的数据,chartColors 存储了图表的颜色配置。在 methods 中,initECharts 方法用于初始化 ECharts 实例和配置项。

<template>
  <div>
    <!-- ECharts 图表容器 -->
    <div class="chart-container" ref="chart"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  data() {
    return {
      // 模拟的图表数据
      chartData: {
        xAxisData: ['A', 'B', 'C'],
        seriesData: [5, 3, 5],
      },
      // 图表颜色配置
      chartColors: ['#3398DB', '#FF6666', '#3CB371', '#FFD700', '#8B4513'],
    };
  },
  mounted() {
    // 使用固定数据配置 ECharts 实例
    this.initECharts();
  },
  methods: {
    initECharts() {
      const chartDom = this.$refs.chart;
      const myChart = echarts.init(chartDom);

      // ECharts 配置项
      const option = {
        title: {
          text: '示例数据',
          left: 'center',
          top: 20,
          textStyle: {
            fontSize: 16,
            fontWeight: 'bold',
          },
        },
        series: [{
          name: '示例数据',
          type: 'pie',
          radius: '55%',
          center: ['50%', '50%'],
          data: this.chartData.xAxisData.map((name, index) => ({
            name,
            value: this.chartData.seriesData[index],
            itemStyle: {
              color: this.chartColors[index % this.chartColors.length],
            },
          })),
          label: {
            show: true,
            formatter: '{b} : {c} ({d}%)',
          },
        }],
      };

      // 使用配置项设置图表
      myChart.setOption(option);
    },
  },
};
</script>

<style scoped>
.chart-container {
  height: 300px;
  /* 设置图表容器的高度 */
}
</style>