快速上手eCharts

  1. 先看效果图
    在这里插入图片描述

  2. 通过npm安装
    npm install echarts --save

  3. 在main.js中引入

import echarts from 'echarts';	//引入eCharts
Vue.prototype.$echarts = echarts	//挂在到vue原型上
  1. 在组件中使用
<template>
    <div id="app">
    	//在绘图前我们需要为 ECharts 准备一个具备高宽的 DOM 容器
        <div id="main" style="width: 100%;height:600px; display: flex"></div>
    </div>
</template>
<script>
export default {
    name: 'eCharts',
    data() {
        return {
            penetrationList: [25, 20, 36, 60, 40, 90, 10, 20], //渗透
        };
    },
    methods: {
        drawChart() {
            // 基于准备好的dom,初始化echarts实例
            let myChart = this.$echarts.init(document.getElementById('main'));
            // 指定图表的配置项和数据
            let option = {
                tooltip: {},
                legend: {
                    data: ['渗透率'],
                    bottom: 'auto',
                },
                xAxis: [
                    {
                        name: '发布行为',
                        nameLocation: 'start',
                        nameTextStyle: {
                            verticalAlign: 'top',
                            lineHeight: 56,
                            color: '#000',
                            fontWeight: 'bold',
                        },
                        type: 'category',
                        data: ['1次', '2次', '3次', '4次', '5次', '6次', '7次', '8次及以上'],
                    },
                ],
                yAxis: [
                    {
                        name: '行为详情',
                        nameTextStyle: {
                            verticalAlign: 'bottom',
                            lineHeight: 56,
                            color: '#000',
                            fontWeight: 'bold',
                            align: 'right',
                        }
                ],
                series: [
                    {
                        name: '渗透率',
                        type: 'bar',
                        barGap: 0,
                        data: this.penetrationList,
                    }
                ],
            };
            myChart.setOption(option, true);
            //eCharts图表响应式
            window.onresize = function () {
                myChart.resize();
            }
        },
    },
    mounted() {
        this.drawChart();
    },
};
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值