echart 3d立体颜色渐变柱状图

这篇具有很好参考价值的文章主要介绍了echart 3d立体颜色渐变柱状图。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

如果可以实现记得点赞分享,谢谢老铁~

1.需求描述

根据业务需求将不同的法律法规,展示不同的3d立体渐变柱状图。

2.先看下效果图

echart 3d立体颜色渐变柱状图,vue,echart 3d,立体渐变柱状图文章来源地址https://www.toymoban.com/news/detail-650297.html

3. 确定三面的颜色,这里我是自定义的颜色
   // 右面生成颜色
    const rightColorArr = ref([
      "#79DED1",
       ...
    ]);
    // 左面生成颜色
    const leftColorArr = ref([
      "#67C3B7", 
      ...
    ]);
    // 顶部生成颜色
    const topColorArr = ref([
      "#ADF4EB",
      ...
    ]);

4.然后绘画三个面对应的函数,且注册
// 绘制左侧面
    const CubeLeft = echarts.graphic.extendShape({
    });
    // 绘制右侧面
    const CubeRight = echarts.graphic.extendShape({
    });
    // 绘制顶面
    const CubeTop = echarts.graphic.extendShape({
    });
    // 注册三个面图形
    echarts.graphic.registerShape("CubeLeft", CubeLeft);
    echarts.graphic.registerShape("CubeRight", CubeRight);
    echarts.graphic.registerShape("CubeTop", CubeTop);
5.重点在renderItem 自定义渲染函数上
 series: [
          {
            type: "custom",
            renderItem: (params, api) => {
              let cubeLeftStyle: any = "";
              let cubeRightStyle: any = "";
              let cubeTopStyle: any = "";
              cubeLeftStyle = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: leftColorArr.value[params.dataIndex],
                },
                {
                  offset: 1,
                  color: leftColorArr.value[params.dataIndex],
                },
              ]);
              cubeRightStyle = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: rightColorArr.value[params.dataIndex],
                },
                {
                  offset: 1,
                  color: rightColorArr.value[params.dataIndex],
                },
              ]);
              cubeTopStyle = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: topColorArr.value[params.dataIndex],
                },
                {
                  offset: 1,
                  color: topColorArr.value[params.dataIndex],
                },
              ]);
              const location = api.coord([api.value(0), api.value(1)]);
              return {
                type: "group",
                children: [
                  {
                    type: "CubeLeft",
                    shape: {
                      api,
                      xValue: api.value(0),
                      yValue: api.value(1),
                      x: location[0],
                      y: location[1],
                      xAxisPoint: api.coord([api.value(0), -80]),
                    },
                    style: {
                      fill: cubeLeftStyle,
                    },
                  },
                  {
                    type: "CubeRight",
                    shape: {
                      api,
                      xValue: api.value(0),
                      yValue: api.value(1),
                      x: location[0],
                      y: location[1],
                      xAxisPoint: api.coord([api.value(0), -80]),
                    },
                    style: {
                      fill: cubeRightStyle,
                    },
                  },
                  {
                    type: "CubeTop",
                    shape: {
                      api,
                      xValue: api.value(0),
                      yValue: api.value(1),
                      x: location[0],
                      y: location[1],
                      xAxisPoint: api.coord([api.value(0), -50]),
                    },
                    style: {
                      fill: cubeTopStyle,
                    },
                  },
                ],
              };
            },
            data: valList.value,
          },
        ],
5.最后看全文吧,这个是vue3 的文件
<template>
  <div class="topCon">
    <div class="tagList left">
      <div class="item" v-for="(item, index) in nameList" :key="index">
        <a-tag :color="rightColorArr[index]" class="tag"
          >TOP {{ index + 1 }}</a-tag
        >
        <span>{{ item }}</span>
      </div>
    </div>
    <div class="right" id="AnalysisLegalTopBar" style="height: 400px"></div>
  </div>
</template>
<script lang="ts">
import { onMounted, toRefs, ref, watch } from "vue";
import * as echarts from "echarts";
type EChartsOption = echarts.EChartsOption;
export default {
  props: {
    data: Array,
  },
  setup(props) {
    const { data } = toRefs<any>(props);
    const myChart = ref<any>(null);
    let valList = ref<any>([]);
    let nameList = ref<any>([]);

    // 右面生成颜色
    const rightColorArr = ref([
      "#79DED1",
      "#75D5AF",
      "#7FD991",
      "#78BF9D",
      "#95D3C9",
      "#84B5D3",
      "#7794C1",
      "#828AD0",
      "#7573D1",
      "#8057D1",
    ]);
    // 左面生成颜色
    const leftColorArr = ref([
      "#67C3B7",
      "#68C39F",
      "#68C27A",
      "#65AD8A",
      "#7BB8AE",
      "#76A6C3",
      "#6789BC",
      "#737ABE",
      "#5A58BC",
      "#7349C6",
    ]);
    // 顶部生成颜色
    const topColorArr = ref([
      "#ADF4EB",
      "#9BEBCC",
      "#9DE6AB",
      "#98DEBD",
      "#A1E5DA",
      "#9DC5DE",
      "#8CACDD",
      "#B0B5E6",
      "#7F7DD0",
      "#8057D1",
    ]);

    // 绘制左侧面
    const CubeLeft = echarts.graphic.extendShape({
      shape: {
        x: 0,
        y: 0,
      },
      buildPath: function (ctx: any, shape) {
        // 会canvas的应该都能看得懂,shape是从custom传入的
        const xAxisPoint = shape.xAxisPoint;
        const c0 = [shape.x + 7, shape.y];
        const c1 = [shape.x - 23, shape.y - 6];
        const c2 = [xAxisPoint[0] - 23, xAxisPoint[1] - 13];
        const c3 = [xAxisPoint[0] + 7, xAxisPoint[1]];
        ctx
          .moveTo(c0[0], c0[1])
          .lineTo(c1[0], c1[1])
          .lineTo(c2[0], c2[1])
          .lineTo(c3[0], c3[1])
          .closePath();
      },
    });
    // 绘制右侧面
    const CubeRight = echarts.graphic.extendShape({
      shape: {
        x: 0,
        y: 0,
      },
      buildPath: function (ctx: any, shape) {
        const xAxisPoint = shape.xAxisPoint;
        const c1 = [shape.x + 7, shape.y];
        const c2 = [xAxisPoint[0] + 7, xAxisPoint[1]];
        const c3 = [xAxisPoint[0] + 25, xAxisPoint[1] - 15];
        const c4 = [shape.x + 25, shape.y - 15];
        ctx
          .moveTo(c1[0], c1[1])
          .lineTo(c2[0], c2[1])
          .lineTo(c3[0], c3[1])
          .lineTo(c4[0], c4[1])
          .closePath();
      },
    });
    // 绘制顶面
    const CubeTop = echarts.graphic.extendShape({
      shape: {
        x: 0,
        y: 0,
      },
      buildPath: function (ctx: any, shape) {
        const c1 = [shape.x + 7, shape.y];
        const c2 = [shape.x + 25, shape.y - 15]; //右点
        const c3 = [shape.x - 5, shape.y - 20];
        const c4 = [shape.x - 23, shape.y - 6];
        ctx
          .moveTo(c1[0], c1[1])
          .lineTo(c2[0], c2[1])
          .lineTo(c3[0], c3[1])
          .lineTo(c4[0], c4[1])
          .closePath();
      },
    });
    // 注册三个面图形
    echarts.graphic.registerShape("CubeLeft", CubeLeft);
    echarts.graphic.registerShape("CubeRight", CubeRight);
    echarts.graphic.registerShape("CubeTop", CubeTop);

    const getOption = () => {
      return {
        backgroundColor: "transparent",
        title: {
          // text: "单位:个",
          textStyle: {
            color: "#79DED1",
            fontWeight: "800",
            fontSize: 16,
          },
          left: "18px",
          top: "1%",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          formatter: function (params, ticket, callback) {
            const item = params[1];
            return item.name + " : " + item.value;
          },
        },
        grid: {
          top: "12%",
          bottom: "3%",
          left: "left",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          show: false,
          data: nameList.value,
          axisLine: {
            show: true,
            lineStyle: {
              color: "#7ebaf2",
            },
          },
          axisTick: {
            show: false,
            length: 9,
            alignWithLabel: true,
            lineStyle: {
              color: "#7DFFFD",
            },
          },
          axisLabel: {
            fontSize: 12,
          },
        },
        yAxis: {
          type: "value",
          show: false,
          min: 0,
          axisLine: {
            show: true,
            lineStyle: {
              color: "#7ebaf2",
            },
          },
          splitLine: {
            show: false,
          },
          splitArea: {
            show: true,
            areaStyle: {
              color: ["rgba(26,50,83,1)", "rgba(30,57,92,1)"],
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            fontSize: 12,
          },
          boundaryGap: ["20%", "20%"],
        },
        series: [
          {
            type: "custom",
            renderItem: (params, api) => {
              let cubeLeftStyle: any = "";
              let cubeRightStyle: any = "";
              let cubeTopStyle: any = "";
              cubeLeftStyle = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: leftColorArr.value[params.dataIndex],
                },
                {
                  offset: 1,
                  color: leftColorArr.value[params.dataIndex],
                },
              ]);
              cubeRightStyle = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: rightColorArr.value[params.dataIndex],
                },
                {
                  offset: 1,
                  color: rightColorArr.value[params.dataIndex],
                },
              ]);
              cubeTopStyle = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: topColorArr.value[params.dataIndex],
                },
                {
                  offset: 1,
                  color: topColorArr.value[params.dataIndex],
                },
              ]);
              const location = api.coord([api.value(0), api.value(1)]);
              return {
                type: "group",
                children: [
                  {
                    type: "CubeLeft",
                    shape: {
                      api,
                      xValue: api.value(0),
                      yValue: api.value(1),
                      x: location[0],
                      y: location[1],
                      xAxisPoint: api.coord([api.value(0), -80]),
                    },
                    style: {
                      fill: cubeLeftStyle,
                    },
                  },
                  {
                    type: "CubeRight",
                    shape: {
                      api,
                      xValue: api.value(0),
                      yValue: api.value(1),
                      x: location[0],
                      y: location[1],
                      xAxisPoint: api.coord([api.value(0), -80]),
                    },
                    style: {
                      fill: cubeRightStyle,
                    },
                  },
                  {
                    type: "CubeTop",
                    shape: {
                      api,
                      xValue: api.value(0),
                      yValue: api.value(1),
                      x: location[0],
                      y: location[1],
                      xAxisPoint: api.coord([api.value(0), -50]),
                    },
                    style: {
                      fill: cubeTopStyle,
                    },
                  },
                ],
              };
            },
            data: valList.value,
          },
          {
            type: "bar",
            label: {
              normal: {
                show: true,
                position: "top",
                fontSize: 16,
                color: "#6C6C6C",
                offset: [2, -25],
              },
            },
            itemStyle: {
              color: "transparent",
            },
            tooltip: {},
            data: valList.value,
          },
        ],
      };
    };

    watch(
      () => data.value,
      (list) => {
        let option_bar: any = getOption();
        list.forEach((item, index) => {
          nameList.value.push(item.name);
          valList.value.push(item.value);
        });
        option_bar && myChart.value.setOption(option_bar);
      }
    );
    onMounted(() => {
      // 基于准备好的dom,初始化echarts实例
      var chartDom: any = document.getElementById("AnalysisLegalTopBar");
      myChart.value = echarts.init(chartDom);

      window.addEventListener("resize", () => {
        myChart.value.resize();
      });
    });

    return {
      nameList,
      rightColorArr,
    };
  },
};
</script>
<style lang="less" scoped>
.topCon {
  display: flex;
  justify-content: center;
  align-items: center;
  .left {
    width: 30%;
    .item {
      display: flex;
      align-items: center;
    }
  }
  .right {
    width: 70%;
  }
  .tagList {
    .tag {
      width: 46px;
      height: 23px;
      border-radius: 4px;
      font-size: 10px;
      font-weight: 500;
      line-height: 20px;
      margin: 4px 0px;
      margin-right: 10px;
      color: #fff;
      background: rgba(121, 222, 209, 0.39);
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>

收工!谢谢老铁们的点赞收藏~

到了这里,关于echart 3d立体颜色渐变柱状图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue使用echarts与echarts-gl实现3d地图与 3d柱状图

    目录 前言 一、下载echarts与echarts gl 二、vue引入与页面使用 1.引入 2.页面引入echarts-gl 三、下载地图数据 四、使用地图 1、html初始化地图放入位置: 2、data创建变量 3、创建地图 4、钩子函数渲染地图 5、渲染完成效果 总结 提示:本项目使用vue,请提前搭建好vue项目 本次需求

    2024年02月12日
    浏览(29)
  • ECharts: 绘制立体柱状图【圆柱体】

    其中里面的柱体渐变色是通过 ECharts中内置的渐变色生成器 echarts.graphic.LinearGradient 可以用来设置渐变色. Documentation - Apache ECharts

    2024年02月13日
    浏览(42)
  • vue+echarts——实现3D地图+3D柱状图 效果——粗糙代码记录——技能提升

    最近看到同事在弄下面的这个图,这个图是从网上看到的,是某个网站的收费项目: 所以,最后的决定是通过 echarts 中的 3D地图 来写。但是写出来的效果不慎好看。功能是可以实现的。 初版效果图如下: 直接上代码: 我这边是存储到当前文件夹中了。。。 背景颜色是 ec

    2024年02月09日
    浏览(36)
  • plt绘制3D渐变填充柱状图

     

    2024年02月15日
    浏览(27)
  • python读取excel数据并用双y轴绘制柱状图和折线图,柱子用渐变颜色填充

    往期python绘图合集: python绘制简单的折线图 python读取excel中数据并绘制多子图多组图在一张画布上 python绘制带误差棒的柱状图 python绘制多子图并单独显示 python读取excel数据并绘制多y轴图像 python绘制柱状图并美化|不同颜色填充柱子 python随机生成数据并用双y轴绘制两条带误差

    2024年02月10日
    浏览(35)
  • echarts动态渲染柱状图背景颜色以及顶部数值

     众所周知 柱状图的背景色在series下的 itemStyle 的color下修改  不同数据让每个柱状图背景颜色不同  这个时候就需要自定义  所以我在color后跟了一个箭头函数  里面的参数params跟formatter里的是一样的  可以打印出来 看下里面有什么值  我打印了一下  所以这个时候就可以根

    2024年02月04日
    浏览(38)
  • vue+echart实现3d地图可拖拽、缩放、区域填充颜色(geo3D)

    功能背景 一个略微比2d地图炫酷一些的3d地图, 1、可对区域进行不同颜色填充。 2、可拖拽缩放地图 3、鼠标悬停高亮某区域。 (注意:当开启了鼠标悬停series,并高亮某个数据的时候,会导致地图的拖拽缩放出现卡顿,因为相当于是事件重叠了。。。目前还没想到好的解决方

    2024年02月13日
    浏览(37)
  • vue2.x-echarts公共组件封装--简易篇(3d柱状图,炫酷仪表盘,折线,曲线图)

    更新一下之前写的echarts简单图表公共组件的封装,该组件可以实现自适应展示效果 废话不多说,上代码: vue-echarts通用组件 下面的一个混入文件是用来实现,窗口改变echarts自适应的js文件: 接下来是debounce.js 下面直接上代码:父组件调用+展示效果 截图: 下面是一个仪表盘

    2023年04月13日
    浏览(58)
  • echarts-3D立体饼图(1)

    先看效果图 1、echarts的版本使用的是: script src=\\\"https://cdn.bootcdn.net/ajax/libs/echarts/5.4.1/echarts.min.js\\\"/script script src=\\\"https://cdn.bootcdn.net/ajax/libs/echarts-gl/2.0.8/echarts-gl.js\\\"/script 2、饼图可自旋转,鼠标移上也可转动,不想让旋转grid3D:{viewControl:{autoRotate:false}} 3、 3D饼图主义echarts的

    2024年02月09日
    浏览(25)
  • echarts 3D立体图(江苏版)

    npm install echarts@4.9.0 echarts-gl@1.0.1 --legacy-peer-deps 安装echarts插件和echarts 3D地图插件 配置main.js 新建vue文件 如需改样式点这里 npm install echarts@4.9.0 echarts-gl@1.0.1 --legacy-peer-deps 安装echarts插件和echarts 3D地图插件 配置main.js 新建vue文件 如需改样式点这里

    2024年02月12日
    浏览(28)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包