Echarts实现3D柱状图

Echarts实现3D柱状图


1、安装Echarts

npm i echarts

2、进行以下配置

<template>
  <div class="page">
    <div ref="chartDom" class="bar" id="chartOne"></div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { onMounted } from "vue";

onMounted(() => {
  getEcharts3DBar();
});

function getEcharts3DBar() {
  const chartDom = document.getElementById("chartOne");
  const myChart = echarts.init(chartDom);
  // 产值
  const zzx1 = [27, 38, 41, 21, 27];
  const zx = zzx1.map((item) => {
    return 100 - item;
  })

  var barWidth = 40;
  let option = {
    backgroundColor: "#010243",
    // tooltip: {
    //   trigger: "axis",
    //   axisPointer: {
    //     // 坐标轴指示器,坐标轴触发有效
    //     type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
    //   },
    //   formatter: function (e) {
    //     // console.log(e);
    //     var str =
    //       e[6].axisValue +
    //       "<br>" +
    //       "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
    //       e[6].color.colorStops[0].color +
    //       ";'></span>" +
    //       "" +
    //       e[6].seriesName +
    //       " : " +
    //       e[6].value +
    //       "%<br>" +
    //       "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
    //       e[8].color.colorStops[0].color +
    //       ";'></span>" +
    //       "" +
    //       e[8].seriesName +
    //       " : " +
    //       e[8].value +
    //       "%";
    //     return str;
    //   },
    // },
    grid: {
      left: "2%",
      right: "4%",
      bottom: "4%",
      top: "16%",
      containLabel: true, // grid 区域是否包含坐标轴的刻度标签
    },
    legend: {
      show: false,
      data: ["计划产值", "实际产值"],
      top: 1,
      textStyle: {
        color: "#00ffff",
        fontSize: 14,
      },
      itemWidth: 12,
      itemHeight: 10,
      itemGap: 35,
      color: "#242424",
      selectedMode: false,
    },
    xAxis: {
      type: "category",
      data: [
        "A",
        "B",
        "C",
        "D",
        "E",
      ],
      axisLine: { // 坐标轴线的样式
        show: true,
        lineStyle: {
          color: "#15205B",
        },
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        textStyle: {
          fontFamily: "Microsoft YaHei",
          color: "#fff", // x轴颜色
          fontWeight: "normal",
          fontSize: "14",
          lineHeight: 22,
        },
        interval: 0, //标签设置为全部显示
        margin: 15,
        lineHeight: 15,
        formatter: function (params) {
          var newParamsName = params + "\n质量合格率";
          //将最终的字符串返回
          return newParamsName;
        },
      },
    },
    yAxis: {
      min: 0,
      max: 100,
      type: "value",

      axisLine: {
        show: true,
        lineStyle: {
          color: "#15205B",
        },
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: "rgba(135,140,147,1)", //左侧显示线
        },
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        formatter: "{value}%",
        textStyle: {
          color: "#c9c9c9",
          fontSize: 14,
        },
      },
    },
    series: [
      // 产值中间正方形
      {
        type: "pictorialBar",
        symbol: "diamond",

        symbolSize: [barWidth, 8],
        symbolOffset: [9.5, -4.5],
        symbolPosition: "end",
        z: 12,
        color: "#3185FF",
        data: zzx1,
      },
      //  产值底部正方形
      {
        type: "pictorialBar",
        symbol: "diamond",
        symbolSize: [barWidth, 8],
        // symbolOffset: [-26, 4],
        symbolOffset: [9.5, 0],
        z: 12,
        color: "#161D6E",
        data: zzx1,
      },
      // 产值上部正方形
      {
        data: [100, 100, 100, 100, 100],
        type: "pictorialBar",
        symbol: "diamond",
        symbolSize: [barWidth, 8],
        // symbolOffset: [-26, -4],
        symbolOffset: [9.5, -4.5],
        color: "#283190",

        symbolPosition: "end",
      },
      // 产值进度柱子
      {
        name: "计划产值",
        type: "bar",
        barWidth: barWidth,
        stack: "1",
        itemStyle: {
          normal: {
            opacity: 0.7,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "#2863D2",
              },
              {
                offset: 1,
                color: "#161D6E",
              },
            ]),
            barBorderRadius: 0,
          },
        },
        label: {
          show: true,
          position: ["-18", "-18"],
          color: "#00f8ff",
          fontSize: 12,
        },
        data: zzx1,
      },
      // 产值进度柱子
      {
        name: "中间的线",
        type: "bar",
        barWidth: 0.5,
        barGap: "-50%",
        itemStyle: {
          normal: {
            opacity: 0.7,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "#2863D2",
              },
              {
                offset: 1,
                color: "#161D6E",
              },
            ]),
          },
        },
        data: zzx1,
      },
      // 产值上面进度柱子
      {
        data: zx,
        type: "bar",
        barWidth: barWidth,
        stack: "1",
        zlevel: -1,
        itemStyle: {
          normal: {
            opacity: 0.7,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "#182075",
              },
              {
                offset: 1,
                color: "#182075",
              },
            ]),
            barBorderRadius: 0,
          },
        },
      }
    ],
  };
  option && myChart.setOption(option);
}
</script>
<style lang="scss" scoped>
.page {
  width: 100%;
  height: 100%;
  .bar {
    width: 800px;
    height: 800px;
  }
}
</style>

3、效果图:
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现echarts3D柱状图,可以参考以下步骤: 1. 首先,你可以查看echarts官方网站,了解echarts自定义图形的详细用法。\[1\] 2. 参考你提供的案例,可以创建左右两个面,也就是两个柱子。为了形成一点对比,可以稍微调整左右两个面的颜色。同时,可以使用"type: 'pictorialBar'"来实现底部和顶部的效果。\[2\] 3. 在代码中,可以设置柱状图的柱宽(barWidth)为一个固定值,例如30。如果改动这个值导致柱子形状变形,可以调整series中每一个对象的symbolOffset的值。\[3\] 4. 对于双柱状图,可以在series数组中定义多个元素,前几个元素表示"本期"柱状图,后几个元素表示"同期"柱状图。每个柱子都由上中下三部分组成,因此需要定义多个series元素来表示柱子的主体部分、底部和顶部。为了达到整体性的效果,每个柱状图的三部分颜色需要统一。\[3\] 通过以上步骤,你可以实现echarts3D柱状图。希望对你有帮助! #### 引用[.reference_title] - *1* [echarts实现3d柱状图的两种方式](https://blog.csdn.net/weixin_69773376/article/details/128199545)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [echarts 3d柱状图](https://blog.csdn.net/xuyanl/article/details/128011860)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [echarts实现3D效果柱状图](https://blog.csdn.net/dqfkkll/article/details/120287486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值