最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

echarts餅圖顯示設(shè)置效果及代碼示例

 更新時(shí)間:2026年05月22日 10:05:05   作者:hang_bro  
餅圖主要是通過扇形的弧度表現(xiàn)不同類目的數(shù)據(jù)在總和中的占比,它的數(shù)據(jù)格式比柱狀圖更簡(jiǎn)單,只有一維的數(shù)值,不需要給類目,這篇文章主要介紹了echarts餅圖顯示設(shè)置效果及代碼示例的相關(guān)資料,需要的朋友可以參考下

上圖

這是最終顯示效果

代碼

<template>
  <div class="w-full h-full py-[10px] px-[20px] flex flex-col gap-[10px]">
    <!-- 上 -->
    <div class="flex flex-col flex-1 bg-white rounded-[6px] px-[18px] py-[20px] shadow-[0px_0px_8px_rgba(0,0,0,0.16)]">
      <div class="flex items-center">
        <img src="@/assets/images/layout/yunhe/dashboard_title.png" class="w-[4px] h-[16px] mr-[10px]" alt="" />
        <h2 class="text-[18px] font-bold">單位匯總</h2>
      </div>
      <div class="flex-1 flex">
        <!-- 左 -->
        <div class="flex-1 flex flex-col items-center justify-center" style="border-right: 2px dashed #dfdfdf">
          <div
            class="flex items-end text-[20px] h-[51px] text-[#1e1e1e] w-[510px] bg-[url('@/assets/images/layout/yunhe/dashboard_top_bg.png')] bg-no-repeat bg-bottom bg-size-[510px_24px]"
          >
            <img
              src="@/assets/images/layout/yunhe/dashboard_top_left.png"
              class="w-[77px] h-[51px] ml-[67px] mr-[27px]"
              alt=""
            />
            <div class="mb-[5px]">
              <span>頻繁停電用戶數(shù)</span>
              <span class="font-bold ml-[31px] mr-[27px] text-[#08a279] text-[24px]">6000</span>
              <span>戶</span>
            </div>
          </div>
          <div ref="leftPieChartRef" class="flex-1 w-full flex items-center justify-center"></div>
        </div>
        <!-- 右 -->
        <div class="flex-1 flex flex-col items-center justify-center">
          <div
            class="flex items-end text-[20px] h-[51px] text-[#1e1e1e] w-[510px] bg-[url('@/assets/images/layout/yunhe/dashboard_top_bg.png')] bg-no-repeat bg-bottom bg-size-[510px_24px]"
          >
            <img
              src="@/assets/images/layout/yunhe/dashboard_top_right.png"
              class="w-[77px] h-[51px] ml-[67px] mr-[27px]"
              alt=""
            />
            <div class="mb-[5px]">
              <span>昨日發(fā)生停電戶數(shù)</span>
              <span class="font-bold ml-[31px] mr-[27px] text-[#08a279] text-[24px]">6000</span>
              <span>戶</span>
            </div>
          </div>
          <div ref="rightPieChartRef" class="flex-1 w-full flex items-center justify-center">1</div>
        </div>
      </div>
    </div>
   
    </div>
    <!--  -->
  </div>
</template>
<script lang="ts" setup>
import { useEcharts, EchartsOption } from '@/hooks/useEcharts'
import { useEchartsOption } from '@/hooks/useEchartsOption'
import dashboardPieBg from '@/assets/images/layout/yunhe/dashboard_pie_bg.png'
import * as echarts from 'echarts'
const tableData = ref<any[]>([])
const chartData = ref<any[]>([])
const loading = ref(false)
const barChartRef = ref()
const leftPieChartRef = ref()
const rightPieChartRef = ref()


const getLeftPieOption = (): EchartsOption => {
  return {
    color: ['#08a279', '#ff6600', '#50b9ef'],
    tooltip: {
      trigger: 'item',
    },

    graphic: [
      {
        type: 'image',
        left: 'center', //調(diào)整圖片位置
        top: 'center', //調(diào)整圖片位置
        z: -10, //確保圖片在餅圖下方
        //設(shè)置圖片樣式
        style: {
          image: dashboardPieBg,
          width: 280 * 1.3, // 圖片寬度
          height: 226 * 1.3, // 圖片高度
        },
      },
    ],

    series: [
      {
        type: 'pie',
        radius: ['55%', '60%'],
        center: ['50%', '50%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 50,
          borderColor: '#fff',
          borderWidth: 1,
        },
        label: {
          show: true,
          fontSize: 16,
          color: '#1e1e1e',
          verticalAlign: 'middle',
          // 啟用富文本(關(guān)鍵配置)
          rich: {
            // 定義名稱樣式
            text: {
              fontSize: 14,
              color: '#1e1e1e',
              padding: [5, 5, 5, 0], // 上右下左內(nèi)邊距
              align: 'left', // 富文本內(nèi)部左對(duì)齊
            },
            textRight: {
              fontSize: 14,
              color: '#1e1e1e',
              padding: [5, 5, 5, 0], // 上右下左內(nèi)邊距
              align: 'right', // 富文本內(nèi)部右對(duì)齊
            },
            // 2次
            count2: {
              fontSize: 17,
              fontWeight: 'bold',
              color: '#08a279',
              align: 'left', // 統(tǒng)一左對(duì)齊
            },
            // 3-8次
            count3to8: {
              fontSize: 17,
              fontWeight: 'bold',
              color: '#ff6600',
              align: 'left', // 補(bǔ)充左對(duì)齊,避免默認(rèn)居中
            },
            // 8次以上
            count8More: {
              fontSize: 17,
              fontWeight: 'bold',
              color: '#50b9ef',
              align: 'left', // 補(bǔ)充左對(duì)齊
            },
          },
          // 重構(gòu) formatter:移除無效空標(biāo)簽,簡(jiǎn)化邏輯
          formatter: (params) => {
            // 統(tǒng)一獲取樣式名,簡(jiǎn)化邏輯
            let styleName = ''
            if (params.name == '2次') styleName = 'count2'
            else if (params.name == '3-8次') styleName = 'count3to8'
            else if (params.name == '8次以上') styleName = 'count8More'

            const content = `{${styleName}|${params.value}} {text|戶} {${styleName}|${params.percent}} {text|%}`

            // 最終返回:名稱換行 + 數(shù)值內(nèi)容,無多余空標(biāo)簽
            return `{${params.name == '2次' ? 'textRight' : 'text'}|${params.name}}\n${content}`
          },
        },
        labelLine: {
          show: true,
          length: 20,
          length2: 130,
          // smooth: true,
          lineStyle: {
            color: '#dfdfdf',
            width: 1.5,
          },
        },
        labelLayout: function (params: any) {
          const isLeft = params.labelRect.x < leftPieChartInstance.value.getWidth() / 2
          const points = params.labelLinePoints
          // Update the end point.
          points[2][0] = isLeft ? params.labelRect.x : params.labelRect.x + params.labelRect.width
          return {
            labelLinePoints: points,
          }
        },
        data: [
          { value: 3000, name: '2次' },
          { value: 2000, name: '3-8次' },
          { value: 1000, name: '8次以上' },
        ],
      },
    ],
  }
}

const { instance: leftPieChartInstance } = useEcharts(leftPieChartRef, getLeftPieOption())

const getList = () => {
  loading.value = true
  tableData.value = Array.from({ length: 40 }, (_, index) => ({
    gdsName: `供電所${index + 1}`,
    twoTimes: `${index * 100}`,
    threeToEightTimes: `${index * 200}`,
    eightTimesMore: `${index * 300}`,
    threeTimesMoreRatio: `${index * 400}`,
  }))

  loading.value = false
}
const getChartData = () => {
  chartData.value = [
    { value: 16, name: '一級(jí)預(yù)警' },
    { value: 27, name: '二級(jí)預(yù)警' },
    { value: 38, name: '三級(jí)預(yù)警' },
    { value: 22, name: '四級(jí)預(yù)警' },
  ]
  barChartInstance.value?.setOption(getBarOption())
}
const getLeftPieChartData = () => {}

onMounted(() => {
  getList()

  getLeftPieChartData()
})
</script>
<style lang="scss" scoped></style>

記錄一下

總結(jié)

到此這篇關(guān)于echarts餅圖顯示設(shè)置效果及代碼示例的文章就介紹到這了,更多相關(guān)echarts餅圖顯示設(shè)置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

乐安县| 柘荣县| 定结县| 昭苏县| 松溪县| 钟山县| 正定县| 客服| 广昌县| 贵溪市| 大方县| 横山县| 棋牌| 阿坝| 车致| 墨竹工卡县| 晋江市| 分宜县| 揭东县| 应城市| 繁昌县| 滕州市| 六安市| 永新县| 丰城市| 前郭尔| 海丰县| 新巴尔虎右旗| 商河县| 新干县| 榆中县| 长宁县| 黑龙江省| 河东区| 永顺县| 晋城| 台中市| 文昌市| 健康| 河南省| 剑川县|