Echarts雷达图单独设置拐点颜色,边框颜色,区域颜色

html 复制代码
<template>
 <div id="echartBasic"></div>
</template>
<script>
import * as echarts from 'echarts'
export default {
 mounted() {
    var chartDom = document.getElementById('echartBasic')
    var myChart = echarts.init(chartDom)
    const dataObject = [
      {
        name: 'E',
        value: 3000
      },
      {
        name: 'S',
        value: 3000
      },
      {
        name: 'T',
        value: 3000
      },
      {
        name: 'J',
        value: 2000
      },
      {
        name: 'I',
        value: 3000
      },
      {
        name: 'N',
        value: 2500
      },
      {
        name: 'F',
        value: 3500
      },
      {
        name: 'P',
        value: 4000
      }
    ]
    const dataArray = dataObject.map(n => n.value)
    const minNum = Math.min(...dataArray)
    const maxNum = Math.max(...dataArray)
    const zhongNum = (maxNum - minNum) / 3 + minNum
    const option = {
      title: {},
      legend: {
        data: []
      },
      radar: [
        // 虚线
        {
          center: ['50%', '50%'],
          radius: 70,
          shape: 'circle',
          splitNumber: 4,
          color: ['#FFA939'],
          axisName: {
            formatter: '{value}',
            fontSize: 16,
            fontWeight: 'bolder',
            color: 'rgba(1, 242, 182, 1)'
          },
          splitArea: {
            areaStyle: {
              color: ['transparent', 'transparent', 'rgba(114, 172, 209, 0)', 'transparent', 'rgba(114, 172, 209, 0)']
            }
          },
          axisLine: {
            lineStyle: {
              color: '#E3E3E3'
            }
          },
          splitLine: {
            lineStyle: {
              color: '#E3E3E3',
              type: 'dashed' //dashed  solid dotted 射线类型【实线 虚线】
            }
          },
          indicator: dataObject.map(n => ({
            name: n.name,
            max: maxNum,
            color: n.value >= zhongNum ? '#01F2B6' : '#D9D9D9'
          }))
        },
        // 实线
        {
          center: ['50%', '50%'],
          radius: 70,
          indicator: dataObject.map(() => ({max: maxNum})),
          splitNumber: 1,
          shape: 'circle',
          splitArea: {
            show: false
          },
          axisLine: {
            show: false
          },
          splitLine: {
            lineStyle: {
              color: '#E3E3E3',
              type: 'solid',
              width: 4
            }
          }
        }
      ],
      series: [
        {
          name: 'Budget vs spending',
          type: 'radar',
          data: [
            // 真实的
            {
              symbol: 'none',
              value: dataArray,
              itemStyle: {
                normal: {
                  color: 'rgba(25, 255, 198, 0.8)' //拐点颜色
                }
              },
              lineStyle: {
                width: 2,
                labelLine: {
                  color: 'rgba(25, 255, 198, 0.8)' //拐点边框颜色
                }
              },
              areaStyle: {
                // 区域颜色
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {offset: 0, color: 'rgba(171, 255, 129, 1)'},
                  {offset: 1, color: 'rgba(25, 255, 198, 1)'}
                ])
              }
            },
            // 虚假的
            {
              symbol: 'none',
              value: dataObject.map(() => zhongNum),
              itemStyle: {
                normal: {
                  color: 'rgba(182, 235, 255, 0.5)' //拐点颜色
                }
              },
              lineStyle: {
                width: 2,
                labelLine: {
                  color: 'rgba(182, 235, 255, 0.5)' //拐点边框颜色
                }
              },
              areaStyle: {
                // 区域颜色
                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.1, [
                  {offset: 0, color: 'rgba(226, 249, 255, 0.5)'},
                  {offset: 1, color: 'rgba(182, 235, 255, 0.5)'}
                ])
              }
            },
            // 拐点
            ...dataObject.map((n, index) => {
              return {
                type: 'radar',
                // 除了当前的,其他的设置无限大
                value: dataObject.map((_, i) => (i == index ? maxNum : maxNum * 100)),
                z: 2,
                itemStyle: {
                  normal: {
                    color: n.value >= zhongNum ? '#01F2B6' : '#D9D9D9'
                  }
                },
                lineStyle: {
                  width: 0,
                  labelLine: {
                    show: false //隐藏标示线
                  }
                }
              }
            })
            // {
            //   value: dataObject.map(() => maxNum),
            //   itemStyle: {
            //     normal: {
            //       color: '#01F2B6'
            //     }
            //   },
            //   lineStyle: {
            //     width: 0,
            //     labelLine: {
            //       show: false //隐藏标示线
            //     }
            //   }
            // }
          ]
        }
      ]
    }
    option && myChart.setOption(option)
  },
}
</script>
<style>
   #echartBasic {
      width: 210px;
      height: 210px;
      margin: 10px auto 8px auto;
    }
</style>
相关推荐
是你的小橘呀13 小时前
深入理解 JavaScript 预编译:从原理到实践
前端·javascript
风止何安啊13 小时前
栈与堆的精妙舞剧:JavaScript 数据类型深度解析
前端·javascript
用户479492835691513 小时前
Chrome DevTools MCP:让 AI 助手直接操作浏览器开发工具
前端·javascript·chrome
Rysxt_14 小时前
Vuex 教程 从入门到实践
前端·javascript·vue.js
xuehuayu.cn15 小时前
js es6 class 类中的值是异步赋值, 子类中如何获取这个值?
javascript·es6
威风的虫15 小时前
ES6 数组方法:告别循环,拥抱函数式编程
开发语言·前端·javascript
小杨快跑~15 小时前
ES6 Promise:告别回调地狱的异步编程革命
前端·javascript·ecmascript·es6
码界筑梦坊15 小时前
240-基于Python的医疗疾病数据可视化分析系统
开发语言·python·信息可视化·数据分析·毕业设计·echarts
stevenzqzq15 小时前
Android Hilt 入门教程_传统写法和Hilt写法的比较
android
wuwu_q15 小时前
用通俗易懂方式,详细讲讲 Kotlin Flow 中的 map 操作符
android·开发语言·kotlin