echarts在vue中的使用

本文详细介绍如何在项目中集成并使用ECharts进行数据可视化,包括安装、配置、实例化图表及自定义样式等关键步骤。

1.引入

命令行运行:

npm install echarts --save

2.配置:

在main.js中加入

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

3.在模块中的使用:

写一个html

<template>
  <div id="chartId" class="wh100percent"></div>
</template>

在script标签里定义echarts对象

封装一个方法echarts方法

      drawCharts() {
        let _that = this
        let xData = ['粥', '小笼包', '八宝粥', '炸酱面']
        let yData = ['28', '35', '38', '49']
        myChart = this.$echarts.init(document.getElementById(this.chartId))
        myChart.setOption(
          {
            angleAxis: {
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#00567D'
                }
              },
              axisLabel: {
                color: '#fff'
              },
              splitLine: {
                lineStyle: {
                  color: '#00567D'
                }
              },
              min: 0,
              max: 120,
              interval: 25
            },
            radiusAxis: {
              type: 'category',
              data: xData,
              z: 100,
              axisLabel: {
                color: '#fff'
              }
            },
            polar: {
            },
            tooltip: {
              trigger: 'item',
              formatter: function (params, ticket, callback) {
                return params.name + ' : ' + _that.toolTipData[params.dataIndex] + ' (' + params.data + '%)'
              }
            },
            series: [{
              type: 'bar',
              data: yData,
              coordinateSystem: 'polar',
              name: 'A',
              stack: 'a',
              itemStyle: {
                normal: {
                  // 定制显示(按顺序)
                  color: function (params) {
                    var colorList = ['#97e7ff', '#75f5ff', '#00deff', '#0093ff', '#2a5fcf']
                    return colorList[params.dataIndex]
                  }
                }
              }
            }]
          }
        )
        $(window).resize(function () {
          myChart.resize()
        })
      }

 

4.在creat或者mounted生命周期中调用

this.drawCharts()

 

 

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值