elementUi 使用echarts

1、安装echarts

npm install echarts --save

2、引入echarts

// 引入 echarts
import echarts from 'echarts'
// 全局注册组件
Vue.prototype.$echarts = echarts

3、使用

<template>
	<div  class="test2" style="height:600px;" :style="{width:barChartWidth?width:barChartWidth:'500px'}">
      <div id="barChart" style="width:100%;height:100%;float:left" />
    </div>
</template>

创建图表,如果后台返回的数据不是标准的,需要根据实际情况处理图表数据

drawEcharts() {
      const myChart = document.getElementById('barChart')
       //动态设置图表的宽高
      myChart.style.width = this.barChartWidth
      this.barChart = this.$echarts.init(myChart, { width: this.barChartWidth, height: '400px' })
      this.barChart.setOption({
        tooltip: {
          trigger: 'axis',
          // formatter: '{a}',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          x: 25,
          y: 45,
          x2: 5,
          y2: 20,
          borderWidth: 1
        },
        legend: {
          data: ['已完工', '已交付施工且施工正常', '已交付但施工暂未进场', '未交付', '交付后遇阻工无法正常施工']
        },
        xAxis: [
          {
            type: 'category',
            axisTick: { show: false },
            data: this.chartxAxisLabel, //x轴label
            axisLabel: {
              show: true,
              textStyle: {
                color: '#ef4f4a', // 更改坐标轴文字颜色
                fontSize: 14, // 更改坐标轴文字大小
                fontWeight: 500
              }
            }

          }
        ],
        yAxis: [
          {
            minInterval: 1,
            type: 'value',
            textStyle: {
              color: '#f00', // 更改坐标轴文字颜色
              fontSize: 16 // 更改坐标轴文字大小
            }
          }
        ],
        series: [...this.barChartData]//图表数据
      })
    },

uniapp中,如果使用echarts,可以先定制所需图表资源,定制图表
使用时先导入

import $echarts from '@/components/echarts/echarts.min.js';
//调用 $echarts.init(xxx)

h5端或小程序tooltip不能显示,无法解析html, 需要设置tooltip的renderMode属性为richText(测试h5端4.2.1版本有tooptip)

当图表外层的 dom 被设置为 ‘overflow: hidden’,或者移动端窄屏,导致 tooltip 超出外界被截断时,此时设置tooltip 的confine属性,是否将 tooltip 框限制在图表的区域内

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值