echart 配置

显示echarts数据千位符

<template>
  <div id="vulnerabilityLevel" class="vulnerabilityLevel" />
</template>

<script>
import * as echarts from 'echarts'
import {
    reportByLevel } from '../../../api/coraxObj'
export default {
   
  name: 'VulnerabilityLevel',
  props: ['scan_task_id'],
  data() {
   
    return {
   
      dataList: ''
    }
  },
  mounted() {
   
    this.getRreportByLevel()
  },
  methods: {
   

    getRreportByLevel() {
   
      reportByLevel({
    scan_task_id: this.scan_task_id }).then(res => {
   
        this.dataList = res.results.data
        // 初始化ecarts
        this.initChart()
      })
    },
    initChart() {
   
      // 基于准备好的dom,初始化echarts实例
      const myChart = echarts.init(
        document.getElementById('vulnerabilityLevel')
      )
      const option = {
   
        title: {
   
          text: '缺陷数量统计',
          subtext: '单位:个',
          textStyle: {
   
            // 文字颜色
            color: '#333333',
            // 字体风格,'normal','italic','oblique'
            fontStyle: 'normal',
            // 字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
            fontWeight: 'bold',
            // 字体系列
            fontFamily: 'sans-serif',
            // 字体大小
            fontSize: '1rem'
          },
          subtextStyle: {
    // 副标题文本样式{"color": "#aaa"}
            fontSize: '0.8rem'

          }
        },
        // 提示信息
        tooltip: {
   
          trigger: 'item'
        },
        legend: {
   
          orient: 'vertical',
          left: 'right',
          top: 'bottom'
        },
        series: [
          {
   
            // 显示数据
            label: {
   
              formatter: '{c}   ({per|{d}%})\n',
              minMargin: 1,
              edgeDistance: 2,
              lineHeight: 15,

              rich: {
   
                time: {
   
                  fontSize: 10,
                  color: '#999'
                }
              }
            },
            // 设置数据上面的线
            labelLayout: function(params) {
   
              console.log(params)
              var isLeft = params.labelRect.x < myChart.getWidth() / 2
              var points = params.labelLinePoints
              // Update the end point.
              points[2][0] = isLeft
                ? params.labelRect.x
                : params.labelRect.x + params.labelRect.width

              return {
   
                labelLinePoints: points
              }
            },
            top: '24',
            type: 'pie',
            radius: '55%',
            // 数据
            data: [
              {
   
                value: this.dataList.high,
                name: '高',
                itemStyle: {
   
                  color: '#FF7279'
                }
              },
              {
   
                value: this.dataList.Medium,
                name: '中',
                itemStyle: {
   
                  color: '#FFC73E'
                }
              },
              {
   
                value: this.dataList.Low,
                name: '低',
                itemStyle: {
   
                  color: '#61DFC4'
                }
              }
            ],
            emphasis: {
   
              itemStyle: {
   
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            // 设置线的样式
            itemStyle: {
   
              normal: {
   
                // 设置线的长度和位置
                label: {
   
                  minMargin: 1,
                  edgeDistance: 2,
                  lineHeight: 15,
                  rich: {
   
                    time: {
   
                      fontSize: 10,
                      color: '#999'
                    }
                  },
                  // 设置线上的数据的位置
                  position: 'outside',
                  padding: [-10, 10, 10, 10],
                  // 添加千位符
                  formatter: function(p) {
   
                    let value = p.value
                    if (value > 999) {
   
                      const parts = value.toString().split('.')
                      parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
                      value = parts.join('.')
                    }
                    const res = value + ' (' + p.percent + '%)'
                    return res
                  }
                }
              }
            },
            // 设置线的行高
            labelLine: {
   
              length: 15,
              length2: 3,
              maxSurfaceAngle: 80
            }

          }
        ]
      }
      myChart.setOption(option)
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
   
        myChart.resize()
      })
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值