大飞_dafei

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

Vue 中 实现一个简单的 echarts

vue 中 实现一个简单的 echarts

01) vue 中 实现一个简单的 echarts

复制代码
<template>
    <div>
        <div id="charts_1" style="width: 500px;height: 500px;"></div>
    </div>
</template>
<script>
    import * as ECharts from 'echarts/lib/echarts'; // 引入 ECharts 主模块
    import 'echarts/lib/chart/line'; // 引入折线图。
    import 'echarts/lib/component/tooltip';  // 引入提示框组件。
    import 'echarts/lib/component/title';   // 引入标题组件。
    import 'echarts/lib/component/toolbox'; // 引入工具箱组件。

    export default {
        created() {
            this.$nextTick(() => {
                this.myChart1();
            })
        },
        methods: {
            myChart1() {
                let myChart = ECharts.init(document.getElementById('charts_1'));
                myChart.resize();
                let option = {
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: [820, 932, 901, 934, 1290, 1330, 1320],
                        type: 'line'
                    }]
                };
                myChart.setOption(option)
            }
        },
    };
</script>

<style scoped>

</style>
View Code
复制代码

 

02) ant 气泡卡片中实现一个简单的  echarts

复制代码
<template>
    <div>
        <a-popover title="Title" @visibleChange="handleHoverChange">
            <template slot="content">
                <p>Content</p>
                <p>Content</p>
                <div id="charts_1" style="width: 500px;height: 500px;"></div>
            </template>
            <a-button type="primary">
                Hover me
            </a-button>
        </a-popover>
    </div>
</template>
<script>

    /* 这是ant-design-vue */
    import Vue from 'vue'
    import Antd, {message, Select} from 'ant-design-vue'  //这是ant-design-vue
    import 'ant-design-vue/dist/antd.css'
    Vue.use(Antd);
    /* 这是ant-design-vue */
    
    import * as ECharts from 'echarts/lib/echarts'; // 引入 ECharts 主模块
    import 'echarts/lib/chart/line'; // 引入折线图。
    import 'echarts/lib/component/tooltip';  // 引入提示框组件。
    import 'echarts/lib/component/title';   // 引入标题组件。
    import 'echarts/lib/component/toolbox'; // 引入工具箱组件。

    export default {
        methods: {
            handleHoverChange(isVisible) {
                if (isVisible) {
                    setTimeout(() => {
                        this.$nextTick(() => {
                            this.myChart1();
                        });
                    }, 301)
                }
            },
            myChart1() {
                let myChart = ECharts.init(document.getElementById('charts_1'));
                myChart.resize();
                let option = {
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: [820, 932, 901, 934, 1290, 1330, 1320],
                        type: 'line'
                    }]
                };
                myChart.setOption(option)
            }
        },
    };
</script>

<style scoped>

</style>
View Code
复制代码

 

 03) 暂无数据提示---类型1

复制代码
let option = {
  graphic: {
    type: 'text',
    left: 'center',
    top: '40%',
    style: {
      text: '暂无数据',
      textAlign: 'center',
      fill: '#c0c0c0',
      fontSize: 20,
      fontWeight: 700
    }
  },
};
View Code
复制代码

 

 03-2) 暂无数据提示---类型2

复制代码
let option = {
  title: {
    text: '暂无数据',
    left: 'center',
    top: '50%',
    textStyle: {
      color: '#dda0dd',
      fontSize: 36,
    }
  },
};
View Code
复制代码

 

 

 03-3) 暂无数据提示---类型2

复制代码
let option = {
  color: ['#ff68b1', '#D8D8D8'], // 控制圆环颜色
  series: [
    {
      name: '运动情况',
      type: 'pie',
      radius: ['65%', '70%'],
      data: [ // 控制圆环颜色
        {value: 0, name: ''}
      ]
    }
  ]
};
View Code
复制代码

 

 

 

ECharts官方:

ECharts文档1
ECharts文档2

其他:

a) 基于 Vue2.x 封装的 Echarts 图表组件  
  a-1) 文档地址     
  a-2) 备用文档地址
  a-3) demo演示地址

b) 基于 Vue2.x 和  Vue3.x 封装的 Echarts 图表组件  

  支持Vue2 和 Vue3

  

posted on   大飞_dafei  阅读(321)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示