在vue中使用echarts

项目场景:

在Vue中使用echarts制作图表


安装echarts依赖:

npm install echarts -S

创建图表:

全局引入:
在main.js中

// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
//有的会引入报错或没效果
//建议更换
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

使用:

在Echarts.vue中

<div id="echart-line" :style="{width: '400px', height: '500px'}"></div>

export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart(){
        // 基于准备好的dom,初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('echart-line'))
        // 绘制图表
        myChart.setOption({
            title: { text: 'echarts' },
            tooltip: {},
            //全局取色盘
            color: ["#00f", "#f00", "#0f0"],
            xAxis: {
                data: ["拖鞋","跑步鞋","运动鞋","长筒靴","老爹鞋","板鞋"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [20, 18, 36, 10, 10, 20]
            }]
        });
    }
  },
};

效果:
在这里插入图片描述
一个简单的图表就完成了,后续就需要自己在echarts官网自己找对应的图标,更换内容代码即可
echarts官网:https://echarts.apache.org/zh/index.html

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

野猪佩奇007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值