echarts实例:圆环内衬图

记录下工作中使用echarts做出的特殊组件

js 复制代码
import { defineComponent } from 'vue'

import { COLOR_LIGHT_ORG,} from './createChart'


let props = {
  propData: {
    type: Array,
    default: () => [100, 80, 50],
  },
  legendData: {
    type: Array,
    default: () => [
      { name: '0%-60%', desc: '20天22小时25分钟' },
      { name: '60%-80%', desc: '10天15小时35分钟' },
      { name: '80%以上', desc: '5天15小时35分钟' },
    ],
  },
  barWidth: {
    type: Number,
    default: 20,
  },
  barColorArray: {
    type: Array,
    default: () => ['#FDC13C', '#32FFE1', '#E365FF', COLOR_LIGHT_ORG],
  },
  chartExtraOption: {
    type: Object,
    default() {
      return {}
    },
  },
}


export default defineComponent({
  props,
  data() {
    return {}
  },
  created() {},
  mounted() {
    this.init()
    this.$watch(
      () => this.$props, // 监听整个 props 对象
      () => {
        this.init()
      },
      { deep: true, immediate: false },
    )
  },
  beforeDestroy() {
    this.chart?.dispose?.()
  },
  methods: {
    init() {
      const option = this.getChartOption()
      const dom = this.$refs.chart
      if (!this.chart) {
        this.chart = echarts.init(dom, null, {
          renderer: 'canvas',
        })
      }
      this.chart.setOption(option, true)
    },
    getChartOption() {
      const filtered = this.legendData.map((item, index) => {
        return [item.name, this.propData[index]]
      })
      const maxValue = Math.max(...this.propData)
      return {
        color: this.barColorArray,
        angleAxis: {
          clockwise: false,
          axisLine: {
            show: false,
          },
          splitLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          min: 0,
          max: maxValue * 1.4,
        },
        radiusAxis: {
          type: 'category',
          data: _.map(this.legendData, 'name'),
          z: 10,
          inverse: true,
          axisLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        polar: {
          radius: '100%',
        },
        series: [
          {
            type: 'bar',
            barWidth: this.barWidth,
            stack: 'base',
            data: filtered,
            coordinateSystem: 'polar',
            name: '1',
            colorBy: 'data',
          },
          {
            type: 'bar',
            stack: 'base',
            barWidth: this.barWidth,
            data: this.legendData.map((row) => [row.name, maxValue * 1.25]),
            coordinateSystem: 'polar',
            name: '半透衬底',
            itemStyle: {
              color: '#ffffff08',
            },
          },
        ],
      }
    },
  },
})
相关推荐
小旭952721 小时前
SpringBoot 项目实战:ECharts 数据可视化 + POI Excel 报表导出完整版教程
java·spring boot·后端·信息可视化·echarts
快乐小土豆~~4 天前
echarts柱状图的X轴label过长被重叠覆盖
前端·javascript·vue.js·echarts
军军君014 天前
数字孪生监控大屏实战模板:可视化数字统计展示
前端·javascript·vue.js·typescript·echarts·数字孪生·前端大屏
淡笑沐白4 天前
ECharts入门指南:数据可视化实战
前端·javascript·echarts
_院长大人_4 天前
Vue + ECharts 实现价格趋势分析图
前端·vue.js·echarts
俺不会敲代码啊啊啊7 天前
封装 ECharts Hook 适配多种图表容器
前端·vue.js·typescript·echarts
尘中客11 天前
放弃 Echarts?前端直接渲染后端高精度 SVG 矢量图流的踩坑记录
前端·javascript·echarts·前端开发·svg矢量图·echarts避坑
Dxy123931021613 天前
ECharts折线图入门学习:从基础到实战的完整指南
学习·信息可视化·echarts
yb305小白13 天前
echarts 排名Y轴数据过多出现滚动条,排名柱形条绑定事件
前端·echarts
Dxy123931021613 天前
ECharts入门学习:从零开始打造炫酷数据可视化
学习·信息可视化·echarts