【Echarts】封装几个酷炫(发光)图表

简介: 【Echarts】封装几个酷炫(发光)图表

前言:


以下的代码基于echarts+vue2,我使用的echarts版本是5.3,但是实测更低或更高均可使用。以下组件均已封装。

1.圆环图表


效果如下所示:


image.png

思路:


基于阴影(box-shadow),修改shadowBlur的值

组件代码:


<template>
  <div id="keyleft1" style="height: 200px; width: 200px">{{ leftOne }}</div>
</template>
<script>
import 'echarts-gl'
export default {
  props: {
    leftOne: {
      type: String,
      default: "0"
    },
  },
  data () {
    return {
      numX: "0"
    }
  },
  methods: {
    init () {
      let _that = this
      var chartDom = document.getElementById("keyleft1")
      var myChart = this.$echarts.init(chartDom)
      var option
      var trafficWay = [{
        name: '',
        value: 20
      }, {
        name: '',
        value: 10
      }, {
        name: '',
        value: 30
      }]
      var data = []
      var color = ['#00ffff', '#ff0', '#006ced', '#ffe000', '#ffa800', '#ff5b00', '#ff3000']
      for (var i = 0; i < trafficWay.length; i++) {
        data.push({
          value: trafficWay[i].value,
          name: trafficWay[i].name,
          itemStyle: {
            label: {
              normal: {
                show: false
              }
            },
            normal: {
              borderWidth: 5,
              shadowBlur: 20,
              borderColor: color[i],
              shadowColor: color[i]
            }
          }
        }, {
          value: 2,
          name: '',
          itemStyle: {
            normal: {
              label: {
                show: false
              },
              labelLine: {
                normal: {
                  show: false
                }
              },
              color: 'rgba(0, 0, 0, 0)',
              borderColor: 'rgba(0, 0, 0, 0)',
              borderWidth: 0
            }
          }
        })
      }
      var seriesOption = [{
        name: '',
        type: 'pie',
        clockWise: false,
        radius: [65, 60],
        hoverAnimation: false,
        itemStyle: {
          normal: {
            label: {
              show: false,
              position: 'outside',
              color: '#ddd',
              formatter: function (params) {
                var percent = 0
                var total = 0
                for (var i = 0; i < trafficWay.length; i++) {
                  total += trafficWay[i].value
                }
                percent = ((params.value / total) * 100).toFixed(0)
                if (params.name !== '') {
                  return params.name + '\n' + '\n' + '占百分比:' + percent + '%'
                } else {
                  return ''
                }
              },
            },
            labelLine: {
              length: 30,
              length2: 100,
              show: true,
              color: '#00ffff'
            }
          }
        },
        data: data
      }]
      option = {
        backgroundColor: 'rgba(255,255,255,0)',
        color: color,
        title: {
          text: _that.numX,
          subtext: '',
          top: '46%',
          textAlign: "center",
          left: "49%",
          textStyle: {
            color: '#fff',
            fontSize: 20,
            fontWeight: '600'
          },
          subtextStyle: {
            color: '#fff',
            fontSize: 18,
            fontWeight: '400'
          }
        },
        tooltip: {
          show: false
        },
        legend: {
          icon: "circle",
          orient: 'horizontal',
          // x: 'left',
          data: ['功能区域噪声', '交通噪声', '区域噪声'],
          right: 250,
          top: 100,
          align: 'right',
          textStyle: {
            color: "#fff"
          },
          itemGap: 20
        },
        toolbox: {
          show: false
        },
        series: seriesOption
      }
      option && myChart.setOption(option)
    }
  },
  mounted () {
    this.init()
  },
  watch: {
    leftOne (newValue, oldValue) {
      this.numX = newValue
      this.init()
    }
  },
}
</script>
<style>
</style>

2. 饼图封装


效果如下所示 :


image.png

组件代码如下:


<template>
  <div id="left2" style="height: 280px"></div>
</template>
<script>
import 'echarts-gl'
export default {
  props: {
    leftTwoData: {
      type: String,
      default: "0"
    },
  },
  data () {
    return {
      numX: "0"
    }
  },
  methods: {
    init () {
      let _that = this
      var chartDom = document.getElementById('left2')
      var myChart = this.$echarts.init(chartDom)
      var option
      var img =
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAADGCAYAAACJm/9dAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLz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+jciXj/bQVwLHrmS7M3LT2qTRghT6ORkcODdEhfNAeyFB0schmwY+bWlT9D0LN5DT2rSejZhTyNnu0hwILMrcuAahVGyGJUe3wdHWnbEntvX7SP+F3gMbTUZAC1ywAkgMfQGqZb0TMKaUHP8OvomS7O1rxsqWtdUlOLVoejGdnzgD0S3v8IreGZi4I0fJydabmwHWoKTUR9tKRBitXo0MefkVI4zDxpam5MfL3WhBFSj/Z/nI/W7DQkXNOCdpE9jbbhVsSMbTcYARwFHI2aQ4X+748jQTQDWzKzLmMKCaNv4qvVzxbg2eBve/SLeTowjmg3WQP6NT02yL+Lmg/Lgr9VRGGAypU+SAijg7/DgF0LXLsZiWA2Cp68PgP7ypZarTEKMQzVIOPRr+rWJgivRkPA5cxVaIi1EJ+i2vAJVEOU7WrXtHCN0T3WovU+96DO6OEoksk4FNqn0n9F2tC+iGZUWy4CNuZqUZliYRRmI5pND2fUd0JDwKPRMGVLgfvKiRa0EegF1PxbDnyQq0UVwv8BNYmwIpIWBvwAAAAASUVORK5CYII="
      let arrD = []
      for (const key in _that.numX) {
        if (Object.hasOwnProperty.call(_that.numX, key)) {
          const element = _that.numX[key]
          arrD.push({
            name: key,
            value: element,
          })
        }
      }
      var trafficWay = [
        {
          name: "火",
          value: 2,
        },
        {
          name: "飞机",
          value: 10,
        },
        {
          name: "客车",
          value: 30,
        },
        {
          name: "轮渡",
          value: 40,
        },
      ] || arrD
      var data = []
      var color = [
        "#00ffff",
        "#00cfff",
        "#006ced",
        "#ffe000",
        "#ffa800",
        "#ff5b00",
        "#ff3000",
      ]
      for (var i = 0; i < trafficWay.length; i++) {
        data.push(
          {
            value: trafficWay[i].value,
            name: trafficWay[i].name,
            itemStyle: {
              normal: {
                borderWidth: 5,
                shadowBlur: 20,
                borderColor: color[i],
                shadowColor: color[i],
              },
            },
          },
          {
            value: 2,
            name: "",
            itemStyle: {
              normal: {
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                color: "rgba(0, 0, 0, 0)",
                borderColor: "rgba(0, 0, 0, 0)",
                borderWidth: 0,
              },
            },
          }
        )
      }
      var seriesOption = [
        {
          name: "",
          type: "pie",
          clockWise: false,
          radius: [105, 109],
          hoverAnimation: false,
          itemStyle: {
            normal: {
              label: {
                show: true,
                position: "outside",
                color: "#ddd",
                formatter: function (params) {
                  var percent = 0
                  var total = 0
                  for (var i = 0; i < trafficWay.length; i++) {
                    total += trafficWay[i].value
                  }
                  percent = ((params.value / total) * 100).toFixed(0)
                  if (params.name !== "") {
                    return (
                      "" +
                      params.name +
                      "\n" +
                      "\n" +
                      "" +
                      percent +
                      "%"
                    )
                  } else {
                    return ""
                  }
                },
              },
              labelLine: {
                length: 30,
                length2: 10,
                show: true,
                color: "#00ffff",
              },
            },
          },
          data: data,
        },
      ]
      option = {
        backgroundColor: "rgba(255,255,255,0)",
        color: color,
        title: {
          text: "交通方式",
          top: "48%",
          textAlign: "center",
          left: "49%",
          textStyle: {
            color: "#fff",
            fontSize: 22,
            fontWeight: "400",
          },
        },
        graphic: {
          elements: [
            {
              type: "image",
              z: 3,
              style: {
                image: img,
                width: 178,
                height: 178,
              },
              left: "center",
              top: "center",
              position: [100, 100],
            },
          ],
        },
        tooltip: {
          show: false,
        },
        legend: {
          show: false,
          icon: "circle",
          orient: "horizontal",
          // x: 'left',
          data: ["火车", "飞机", "客车", "轮渡"],
          right: 10,
          bottom: 0,
          align: "right",
          textStyle: {
            color: "#fff",
          },
          itemGap: 10,
        },
        toolbox: {
          show: false,
        },
        series: seriesOption,
      }
      option && myChart.setOption(option)
    }
  },
  mounted () {
    this.init()
  },
  watch: {
    leftTwoData (newValue, oldValue) {
      this.numX = JSON.parse(newValue)
      this.init()
      console.log("leftTwoData---------", this.numX)
    }
  },
}
</script>
<style>
</style>

3.柱状图封装


效果图如下:


image.png

由于和上面的改动不算大,所以只贴核心配置项了。

组件核心配置项如下:


data = [
  {
    name: "常规",
    value: 175.17,
  },
  {
    name: "紧急",
    value: 148.35,
  },
  {
    name: "疑难",
    value: 95.36,
  },
];
xAxisData = [];
seriesData1 = [];
sum = 0;
barTopColor = ["#02c3f1", "#53e568", "#a154e9"];
barBottomColor = [
  "rgba(2,195,241,0.1)",
  "rgba(83, 229, 104, 0.1)",
  "rgba(161, 84, 233, 0.1)",
];
data.forEach((item) => {
  xAxisData.push(item.name);
  seriesData1.push(item.value);
  sum += item.value;
});
option = {
  backgroundColor: "#061326",
  title: {
    text: "多色立体圆柱",
    top: 20,
    left: "center",
    textStyle: {
      color: "#fff",
      fontSize: 20,
    },
  },
  grid: {
    top: "25%",
    bottom: "15%",
  },
  xAxis: {
    data: xAxisData,
    axisTick: {
      show: false,
    },
    axisLine: {
      show: false,
    },
    axisLabel: {
      show: true,
      margin: 25,
      align: "center",
      formatter: function (params, index) {
        return (
          "{a|" +
          ((seriesData1[index] / sum) * 100).toFixed(2) +
          "%}" +
          "\n" +
          "{b|" +
          params +
          "}"
        );
      },
      textStyle: {
        fontSize: 14,
        color: "#ffffff",
        rich: {
          a: {
            fontSize: 12,
            color: "#ffffff",
          },
          b: {
            height: 20,
            fontSize: 14,
            color: "#ffffff",
          },
        },
      },
    },
    interval: 0,
  },
  yAxis: {
    splitLine: {
      show: false,
    },
    axisTick: {
      show: false,
    },
    axisLine: {
      show: false,
    },
    axisLabel: {
      show: false,
    },
  },
  series: [
    {
      name: "柱顶部",
      type: "pictorialBar",
      symbolSize: [26, 10],
      symbolOffset: [0, -5],
      z: 12,
      itemStyle: {
        normal: {
          color: function (params) {
            return barTopColor[params.dataIndex];
          },
        },
      },
      label: {
        show: true,
        position: "top",
        fontSize: 16,
      },
      symbolPosition: "end",
      data: seriesData1,
    },
    {
      name: "柱底部",
      type: "pictorialBar",
      symbolSize: [26, 10],
      symbolOffset: [0, 5],
      z: 12,
      itemStyle: {
        normal: {
          color: function (params) {
            return barTopColor[params.dataIndex];
          },
        },
      },
      data: seriesData1,
    },
    {
      name: "第一圈",
      type: "pictorialBar",
      symbolSize: [47, 16],
      symbolOffset: [0, 11],
      z: 11,
      itemStyle: {
        normal: {
          color: "transparent",
          borderColor: "#3ACDC5",
          borderWidth: 2,
        },
      },
      data: seriesData1,
    },
    {
      name: "第二圈",
      type: "pictorialBar",
      symbolSize: [62, 22],
      symbolOffset: [0, 17],
      z: 10,
      itemStyle: {
        normal: {
          color: "transparent",
          borderColor: barTopColor[0],
          borderWidth: 2,
        },
      },
      data: seriesData1,
    },
    {
      type: "bar",
      itemStyle: {
        normal: {
          color: function (params) {
            return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 1,
                color: barTopColor[params.dataIndex],
              },
              {
                offset: 0,
                color: barBottomColor[params.dataIndex],
              },
            ]);
          },
          opacity: 0.8,
        },
      },
      z: 16,
      silent: true,
      barWidth: 26,
      barGap: "-100%", // Make series be overlap
      data: seriesData1,
    },
  ],
};

4 折线图封装


效果如下:


image.png

配置项:

var lineColor = "#2F5384";
var labelColor = "#74BFE7";
var fontSize = "30";
option = {
  backgroundColor: "#000",
  grid: {
    left: "5%",
    right: "10%",
    top: "15%",
    bottom: "10%",
    containLabel: true,
  },
  tooltip: {
    show: true,
    trigger: "item",
    textStyle: {
      fontSize: fontSize,
    },
  },
  legend: {
    show: true,
    x: "center",
    y: "35",
    itemWidth: 45,
    itemHeight: 18,
    textStyle: {
      color: "#fff",
      fontSize: fontSize,
    },
    data: ["完成率"],
  },
  xAxis: [
    {
      type: "category",
      axisLabel: {
        color: labelColor,
        fontSize: fontSize,
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: lineColor,
          width: 2,
        },
      },
      axisTick: {
        show: false,
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: "#195384",
        },
      },
      data: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
    },
  ],
  yAxis: [
    {
      type: "value",
      name: "(%)",
      nameTextStyle: {
        fontSize: fontSize,
        color: "#fff",
      },
      axisLabel: {
        formatter: "{value}",
        textStyle: {
          color: labelColor,
          fontSize: fontSize,
        },
      },
      axisLine: {
        lineStyle: {
          color: lineColor,
          width: 2,
        },
      },
      axisTick: {
        show: false,
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: "#142B57",
        },
      },
    },
  ],
  series: [
    {
      name: "完成率",
      type: "line",
      stack: "总量",
      symbol: "circle",
      symbolSize: 10,
      smooth: true,
      itemStyle: {
        normal: {
          color: "rgba(3,240,254,1)",
          lineStyle: {
            color: "rgba(3,240,254,1)",
            width: 2,
          },
          areaStyle: {
            //color: '#94C9EC'
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "rgba(3,240,254,.7)",
              },
              {
                offset: 1,
                color: "rgba(3,240,254,0)",
              },
            ]),
          },
          shadowColor: "rgba(3,240,254,1)",
          shadowBlur: 20,
        },
      },
      markPoint: {
        itemStyle: {
          normal: {
            color: "red",
          },
        },
      },
      data: [120, 132, 101, 134, 90, 230, 210, 182, 191, 234, 290, 330],
    },
  ],
};
相关文章
|
4天前
一文带你封装Vue3 Echarts
一文带你封装Vue3 Echarts
一文带你封装Vue3 Echarts
|
2月前
|
资源调度 JavaScript API
vue-element-admin 综合开发五:引入 echarts,封装echarts 组件
这篇文章介绍了如何在vue-element-admin项目中引入并封装ECharts组件,以及如何实现折线图、柱状图和饼图的展示。
125 4
vue-element-admin 综合开发五:引入 echarts,封装echarts 组件
|
2月前
|
小程序 前端开发 JavaScript
微信小程序图表制作利器:ECharts组件的使用与技巧
微信小程序图表制作利器:ECharts组件的使用与技巧
76 1
|
2月前
|
JavaScript
vue中使用echarts绘制双Y轴图表时,刻度没有对齐的两种解决方法
vue中使用echarts绘制双Y轴图表时,刻度没有对齐的两种解决方法
448 0
|
3月前
|
Web App开发 数据可视化 前端开发
Echart的使用初体验,Echarts的基本使用及语法格式,简单图表绘制和使用及图例添加【学习笔记】
本文介绍了ECharts的基本使用和语法格式,包括如何引入ECharts、创建容器、初始化echarts实例对象、配置option参数和一些基础图表的绘制方法。文章还提供了简单图表绘制和使用图例添加的示例代码,以及对ECharts特性和优势的概述。
Echart的使用初体验,Echarts的基本使用及语法格式,简单图表绘制和使用及图例添加【学习笔记】
|
4月前
|
小程序 JavaScript
微信小程序使用echarts图表(ec-canvas)
这篇文章介绍了在微信小程序中使用`ec-canvas`集成echarts图表的方法,包括解决加载时报错的问题、配置图表组件、以及在小程序页面中引入和使用这些图表组件的步骤。
533 1
微信小程序使用echarts图表(ec-canvas)
|
4月前
|
前端开发 数据可视化 JavaScript
Echarts如何实现多图表缩放和自适应?附源码
Echarts如何实现多图表缩放和自适应?附源码
Echarts如何实现多图表缩放和自适应?附源码
|
4月前
Echarts——如何默认选中图表并显示tooltip
Echarts——如何默认选中图表并显示tooltip
88 1
|
4月前
|
XML SQL JavaScript
在vue页面引入echarts,图表的数据来自数据库 springboot+mybatis+vue+elementui+echarts实现图表的制作
这篇文章介绍了如何在Vue页面中结合SpringBoot、MyBatis、ElementUI和ECharts,实现从数据库获取数据并展示为图表的过程,包括前端和后端的代码实现以及遇到的问题和解决方法。
在vue页面引入echarts,图表的数据来自数据库 springboot+mybatis+vue+elementui+echarts实现图表的制作
|
4月前
|
JavaScript
Echarts——VUE中非根节点时不显示图表也无报错
Echarts——VUE中非根节点时不显示图表也无报错
43 1

热门文章

最新文章