echarts 四分之三圆环 样式

const alarmTypeChartsGet = (data) => {
  const colorOptions = [
    {
      label: '桥涵预警',
      barColor: '#f3cf88',
      color: '#E29500',
      unit: '个',
      prop: 'bridge'
    },
    {
      label: '灌排渠预警',
      barColor: '#DF9FE7',
      color: '#C953D7',
      unit: '条',
      prop: 'canal'
    },
    {
      label: '水源井预警',
      barColor: '#96D4EB',
      color: '#00BAFF',
      unit: '个',
      prop: 'water'
    },
    {
      label: '道路预警',
      barColor: '#CCE797',
      color: '#86C212',
      unit: '条',
      prop: 'road'
    }
  ]
  const series: any = []
  let total = 0
  colorOptions.forEach((i, k) => {
    const item = data.find((j) => j.eventTypeName == i.label)
    total += item.eventCount
    const seriseData = Array.from({ length: 4 }, (_i) => 0)
    seriseData[k] = item.eventCount
    series.push({
      type: 'bar',
      barWidth: '50%',
      data: seriseData,
      coordinateSystem: 'polar',
      stack: 'total',
      itemStyle: {
        borderRadius: [0, '50%', 0, '50%']
      },
      label: {
        show: false
      }
    })
  })
  const option = {
    title: {
      text: total,
      left: 'center',
      top: 'center',
      itemGap: 0,
      textStyle: {
        color: '#19abad',
        fontSize: 24,
        lineHeight: 24,
        height: 20,
        fontWeight: 'bold'
      },
      subtext: '预警总数',
      subtextStyle: {
        color: '#19abad',
        fontSize: 16,
        height: 12,
        lineHeight: 16
      }
    },
    polar: {
      radius: ['30%', '80%'],
      center: ['50%', '50%']
    },
    color: colorOptions.map((i) => i.barColor),
    angleAxis: {
      startAngle: 270,
      endAngle: 0,
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      axisTick: {
        show: false
      }
    },
    radiusAxis: {
      type: 'category',
      data: colorOptions.map((i) => i.label),
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        interval: 0,
        formatter: function (params, index) {
          const value = data.find((i) => i.eventTypeName == params).eventCount
          const labelOption: any = colorOptions.find((i) => i.label == params)
          switch (labelOption.prop) {
            case 'road':
              return `{name|${params}}{road|${value}}{unit|${labelOption?.unit}}`
            case 'water':
              return `{name|${params}}{water|${value}}{unit|${labelOption?.unit}}`
            case 'canal':
              return `{name|${params}}{canal|${value}}{unit|${labelOption?.unit}}`
            case 'bridge':
              return `{name|${params}}{bridge|${value}}{unit|${labelOption?.unit}}`
          }
        },
        rich: {
          name: {
            color: '#6D6D6D',
            fontSize: 14,
            fontWeight: 'bold'
          },
          bridge: {
            color: '#E29500',
            fontSize: 16,
            fontWeight: 'bold',
            padding: [0, 8, 0, 8]
          },
          water: {
            color: '#00BAFF',
            fontSize: 16,
            fontWeight: 'bold',
            padding: [0, 8, 0, 8]
          },
          road: {
            color: '#86C212',
            fontSize: 16,
            fontWeight: 'bold',
            padding: [0, 8, 0, 8]
          },
          canal: {
            color: '#C953D7',
            fontSize: 16,
            fontWeight: 'bold',
            padding: [0, 8, 0, 8]
          },
          unit: {
            color: '#6D6D6D',
            fontSize: 12,
            fontWeight: 400
          }
        }
      }
    },
    series
  }
  return option
}

示例图

<think>好的,用户想用Vue实现一个四分之三圆环的弧形进度条。首先,我需要理解四分之三圆环是什么样的。通常,完整的圆环是360度,四分之三就是270度,所以应该是一个从某个起点开始,绘制270度的弧形作为进度条,剩下的90度不显示或者透明。 接下来,考虑如何用Vue来实现。Vue通常结合HTML和CSS,可能还需要使用SVG或者Canvas来绘制图形。SVG在绘制矢量图形方面比较灵活,适合这种进度条。所以可能采用SVG来创建弧形。 首先,确定SVG的结构。需要一个圆弧,可以使用SVG的<path>元素,并通过stroke-dasharray和stroke-dashoffset来实现进度效果。不过因为是四分之三圆环,可能需要调整起始角度,比如从顶部开始,绘制270度的弧。 然后,考虑到进度条的动态变化,可能需要使用Vue的数据绑定,将进度值绑定到stroke-dasharray等属性上。计算弧长的公式可能需要调整,因为通常的圆形进度条是完整的圆,这里只需要270度,所以周长计算不同。例如,周长应该是圆的周长乘以270/360,即3/4。 另外,可能需要使用CSS的transform属性来旋转SVG,使得圆弧的起点在顶部,并且留出四分之一的空间。比如,将整个SVG旋转-135度,这样圆弧从顶部开始,绘制270度后结束在右侧,剩下的四分之一在左侧不显示。 用户可能还需要进度数值的动态显示,比如在圆环中间显示百分比,这可以通过Vue的文本插值实现。 然后,测试代码是否能够正确显示四分之三圆环,并且随着进度值的变化,弧形长度相应改变。可能需要调整stroke-dasharray和stroke-dashoffset的值,确保动画平滑。 最后,检查代码是否存在兼容性问题,或者是否有更简洁的实现方式。例如,使用Vue的computed属性来计算路径的d属性,或者使用CSS动画过渡效果。 总结步骤:创建Vue组件,使用SVG绘制背景和进度条路径,通过Vue绑定动态属性,调整旋转和弧长计算,实现进度变化效果。</think>### Vue实现3/4圆环进度条教程 #### 实现思路 1. 使用SVG的`<path>`元素绘制两个圆弧(背景条和进度条) 2. 通过`stroke-dasharray`和`stroke-dashoffset`实现进度动画 3. 用CSS旋转控制圆弧起始角度 4. 使用Vue响应式数据绑定进度值 #### 完整代码示例 ```vue <template> <div class="progress-container"> <svg :width="size" :height="size"> <!-- 背景圆弧 --> <path :d="trackPath" fill="none" :stroke="trackColor" :stroke-width="strokeWidth" /> <!-- 进度条 --> <path :d="trackPath" fill="none" :stroke="progressColor" :stroke-width="strokeWidth" :stroke-dasharray="dashArray" :stroke-dashoffset="dashOffset" stroke-linecap="round" /> <!-- 进度文字 --> <text x="50%" y="50%" text-anchor="middle" dominant-baseline="middle" class="progress-text" > {{ progress }}% </text> </svg> </div> </template> <script> export default { props: { size: { type: Number, default: 200 }, progress: { type: Number, default: 75 }, strokeWidth: { type: Number, default: 12 }, trackColor: { type: String, default: '#eee' }, progressColor: { type: String, default: '#42b983' } }, computed: { radius() { return (this.size - this.strokeWidth) / 2 }, trackPath() { const startAngle = -135 // 起始角度 const endAngle = 135 // 结束角度(总共270度) return ` M ${this.size/2},${this.strokeWidth/2} a ${this.radius} ${this.radius} 0 1 1 0 ${this.size - this.strokeWidth} a ${this.radius} ${this.radius} 0 1 1 0 -${this.size - this.strokeWidth} ` }, circumference() { return 2 * Math.PI * this.radius * 0.75 // 仅计算3/4周长 }, dashArray() { return this.circumference }, dashOffset() { return this.circumference * (1 - this.progress / 100) } } } </script> <style> .progress-container { transform: rotate(-135deg); /* 旋转容器显示3/4圆 */ } .progress-text { transform: rotate(135deg); /* 反向旋转文字保持正向 */ font-size: 24px; fill: #666; } </style> ``` #### 核心实现说明 1. **圆弧路径计算**:通过`d`属性生成270度的圆弧路径,使用两个半圆弧拼接实现[^1] 2. **进度动画**:`stroke-dashoffset`根据进度百分比动态计算偏移量 3. **旋转控制**:通过CSS旋转容器-135度,使圆弧从正上方开始绘制 4. **响应式设计**:所有尺寸参数均可通过props动态配置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值