首页 > 其他分享 >echarts实现多重环形图

echarts实现多重环形图

时间:2022-11-23 17:35:38浏览次数:52  
标签:多重 false name show color 环形 value data echarts

大屏里有一个多重环形图的展示,设计图效果:

 

echarts没有直接实现的,参考了网上的几种方法,自己修改了一下,主要分两种: 1 环形饼图重叠  2 柱形图结合极坐标系

 

这篇先介绍使用环形饼图实现

 

两种效果图:

 

代码

<template>
  <div>
    <div id="chart" />
    <div id="chart2" />
    <div id="chart3" />
  </div>
</template>
<script setup>
import * as echarts from "echarts";
import { onMounted } from "vue";

onMounted(() => {
  var myChart = echarts.init(document.getElementById("chart"));
  var myChart2 = echarts.init(document.getElementById("chart2"));
  var myChart3 = echarts.init(document.getElementById("chart3"));

  var placeHolderStyle = {
    label: {
      show: false,
      position: "center",
    },
    labelLine: {
      show: false,
    },
    itemStyle: {
      color: "#5b5b5b",
      borderColor: "#5b5b5b",
      borderWidth: 10,
    },
    emphasis: {
      // color: '#dedede',
      // borderColor: '#dedede',
      // borderWidth: 10,
      disabled: true,
      label: {
        show: false,
      },
      labelLine: {
        show: false,
      },
    },
  };
  const labelStyle = (color, length = 100) => {
    return {
      label: {
        // show: false,
        position: "outside",
        formatter: "{a}: {c}",
      },
      labelLine: {
        // show: false,
        length,
        smooth: 0.5,
      },
      itemStyle: {
        borderWidth: BorderWidth,
        shadowBlur: 40,
        borderColor: color,
        shadowColor: "rgba(0, 0, 0, 0)", //边框阴影
      },
    };
  };
  var BorderWidth = "10";

  myChart.setOption({
    backgroundColor: "#333",
    color: ["#53f1f2", "#4ebefd", "#30ed9d", "#faa234", "#fff"],
    legend: {
      show: true,
      orient: "vertical",
      left: "left",
      top: "middle",
      data: ["正常", "次要", "警告", "重要", "严重"],
      textStyle: {
        color: "#fff",
        fontSize: 16,
      },
    },
    series: [
      {
        name: "正常",
        type: "pie",
        clockWise: false, //顺时加载
        hoverAnimation: false, //鼠标移入变大
        radius: [100, 101],
        ...labelStyle("#53f1f2", 50),
        data: [
          {
            value: 3,
            name: "",
            ...placeHolderStyle,
          },
          {
            value: 7,
            name: "70%",
          },
        ],
      },
      {
        name: "次要",
        type: "pie",
        clockWise: false,
        hoverAnimation: false,
        radius: [80, 81],
        // itemStyle: {
        //     normal: {
        //         label: {
        //             show: false,
        //         },
        //         labelLine: {
        //             show: false,
        //             length: 100,
        //             smooth: 0.5,
        //         },
        //         borderWidth: BorderWidth,
        //         shadowBlur: 40,
        //         borderColor: '#4ebefd',
        //         shadowColor: 'rgba(0, 0, 0, 0)', //边框阴影
        //     },
        // },
        ...labelStyle("#4ebefd", 60),
        data: [
          {
            value: 4,
            name: "",
            ...placeHolderStyle,
          },
          {
            value: 6,
            name: "60%",
          },
        ],
      },
      {
        name: "警告",
        type: "pie",
        clockWise: false,
        hoverAnimation: false,
        radius: [60, 61],
        ...labelStyle("#30ed9d", 70),
        data: [
          {
            value: 5,
            name: "",
            ...placeHolderStyle,
          },
          {
            value: 5,
            name: "40%",
          },
        ],
      },
      {
        name: "重要",
        type: "pie",
        clockWise: false,
        hoverAnimation: false,
        radius: [40, 41],
        // itemStyle: {
        //     normal: {
        //         label: {
        //             show: false,
        //         },
        //         labelLine: {
        //             show: false,
        //             length: 100,
        //             smooth: 0.5,
        //         },
        //         borderWidth: BorderWidth,
        //         shadowBlur: 40,
        //         borderColor: '#faa234',
        //         shadowColor: 'rgba(0, 0, 0, 0)', //边框阴影
        //     },
        // },
        ...labelStyle("#faa234", 90),
        data: [
          {
            value: 7,
            name: "",
            ...placeHolderStyle,
          },
          {
            value: 3,
            name: "30%",
          },
        ],
      },
      {
        name: "严重",
        type: "pie",
        clockWise: false,
        hoverAnimation: false,
        radius: [20, 21],
        ...labelStyle("#fff"),
        labelLine: {
          lineStyle: {
            color: "#fff",
          },
          length: 100,
          smooth: 0.5,
        },
        data: [
          {
            value: 6,
            name: "",
            ...placeHolderStyle,
          },
          {
            value: 4,
            name: "30%",
          },
        ],
      },
    ],
  });

  myChart2.setOption({
    title: {
      text: "销售分布",
    },
    tooltip: {},
    legend: {
      data: ["一月", "二月", "三月"],
    },
    polar: {
      radius: ["5%", "40%"],
      //   center: ["50%", "50%"],
    },
    angleAxis: {
      max: 4,
      startAngle: 90,
      axisLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        show: false,
      },
      splitLine: {
        show: false,
      },
    },
    radiusAxis: {
      type: "category",
      data: ["a", "b", "c", "d"],
      axisLabel: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisLine: {
        show: false,
      },
    },
    series: {
      type: "bar",
      showBackground: true,
      colorBy: "data",
      barCategoryGap: 4,
      color: ["#00BDAE", "#88bedb", "#f8dc74", "#ee9665"],
      data: [
        2,
        1.2,
        {
          value: 2.4,
          label: {
            offset: [50, 80],
            rotate: 0,
          },
        },
        {
          value: 2.6,
          label: {
            offset: [0, 60],
          },
        },
      ],
      roundCap: true,
      coordinateSystem: "polar",
      label: {
        show: true,
        position: "middle",
        formatter: "{b}: {c}",
        offset: [100, -50],
        rotate: 0,
      },
      labelLine: {
        show: true,
      },
    },
  });

  const placeItemStyle = {
    label: {
      show: false,
    },
    labelLine: {
      show: false,
    },
    itemStyle: {
      color: "#cbccd0",
    },
    emphasis: {
      label: {
        show: false,
      },
      labelLine: {
        show: false,
      },
    },
  };
  myChart3.setOption({
    title: {
      text: "销售分布",
    },
    tooltip: {},
    legend: {
      data: ["一月", "二月", "三月"],
    },
    // yAxis: {},
    series: [
      {
        name: "销量",
        type: "pie",
        radius: ["65%", "80%"],
        color: ["#afdd8a", "#cbccd0"],
        zlevel: 1,
        hoverAnimation: false, //鼠标移入变大
        data: [
          {
            value: 22,
            name: "一月",
            itemStyle: {
              color: "#afdd8a",
              //   borderRadius: 15,
            },
          },
          {
            value: 64,
            name: "",
            ...placeItemStyle,
          },
        ],
      },
      {
        name: "销量",
        type: "pie",
        radius: ["49%", "64%"],
        color: ["#00BDAE", "#cbccd0"],
        zlevel: 2,
        hoverAnimation: false, //鼠标移入变大
        data: [
          {
            value: 32,
            name: "二月",
            itemStyle: {
              // color: '#00BDAE',
              //   borderRadius: 15,
            },
            labelLine: {
              length: 45,
            },
          },
          {
            value: 54,
            name: "",
            ...placeItemStyle,
          },
        ],
      },
      {
        name: "销量",
        type: "pie",
        radius: ["34%", "48%"],
        color: ["#efb754", "#cbccd0"],
        zlevel: 3,
        hoverAnimation: false, //鼠标移入变大
        itemStyle: {
          color: "#efb754",
          //   borderRadius: 15,
        },
        data: [
          {
            value: 28,
            name: "三月",
            labelLine: {
              length: 70,
            },
          },
          {
            value: 60,
            name: "",
            ...placeItemStyle,
          },
        ],
      },
    ],
  });
});
</script>

<style scoped>
#chart {
  width: 500px;
  height: 400px;
}
#chart2 {
  width: 500px;
  height: 400px;
}
#chart3 {
  width: 500px;
  height: 400px;
}
</style>

 

标签:多重,false,name,show,color,环形,value,data,echarts
From: https://www.cnblogs.com/steamed-twisted-roll/p/16919090.html

相关文章

  • 常用js库和框架(echarts)
    前端库,不管是饼图、柱状图,都可以很轻松的画出来。所需要的准备,就是把数据准备好就可以了。下面一个简单的例子来说明下,1、准备demo文件<head><metacharset="utf-8"/>......
  • 多重背包
    太空电梯奶牛们要去太空了!它们打算用方块建造一座太空电梯。现在它们有\(N\)种方块,第\(i\)种方块有一个特定的高度\(h_i\),一定的数量\(c_i\)。为了防止宇宙射线破坏......
  • ECharts – 饼状图图代码实例及其注释详解
    mytextStyle={color:"#333",//文字颜色fontStyle:"normal",//italic斜体oblique倾斜fontWeight:"normal",//文字粗细boldbolderl......
  • ECharts – 折线图代码实例及注释
    mytextStyle={color:"#333",//文字颜色fontStyle:"normal",//italic斜体oblique倾斜fontWeight:"normal",//文字粗细boldbolderl......
  • ECharts – 柱形图代码实例及其注释详解
    mytextStyle={color:"#333",//文字颜色fontStyle:"normal",//italic斜体oblique倾斜fontWeight:"normal",//文字粗细boldbolderl......
  • 解决ECharts官网打开缓慢的问题
    本章我们将解决在Windows系统中打开ECharts官网缓慢的问题。1、问题描述正常情况下,我们在Windows环境中打开ECharts官网可能会遇到非常缓慢的情况,一直处于加载中,甚至打......
  • ⑧ vue+echarts实现热词分析
    依赖"dependencies":{"echarts":"^4.0.4","echarts-wordcloud":"^1.1.3",},tip:echarts-wordcloud现在有2.0和1.x两个版本,2.0对应echarts5.x版本......
  • 代码随想录算法训练营第四天|24. 两两交换链表中的节点 19.删除链表的倒数第N个节点
     今日任务●24.两两交换链表中的节点●19.删除链表的倒数第N个节点●面试题02.07.链表相交●142.环形链表II●总结详细布置24.两两交换链表......
  • echarts 立体柱状图
     echarts立体柱状图option={"grid":{"top":"0%","bottom":"8%","right":"0%","left":"0%"},"xAxis":{......
  • echarts柱状图经验
    涉及知识点1.动态单位,以及单位的及时变化2.窗口变化,重新渲染echarts3.tooltips自定义4.Y轴刻度过长的处理相关代码<template><divclass="usageAll"><route......