基于Echarts的横向双3D柱形图

此图为效果图

话不多说,直接贴代码 ==>> Echarts 3D柱形图 横向

<div id="CScharts6" style="width:100%;height:100%;"></div>

这是方法

 getCharts() {
            // console.log(target_pct, act_pct)
            var myChart = echarts.init(document.getElementById('CScharts6'));
            let manNumber = [32, 20, 18, 33];
            let womanNumber = [12, 32, 14, 26];
            let xData = ['设备1', '设备2', '设备3', '设备4'];

            let barWidth = 18;
            let manColors = [];
            let womanColors = [];
            for (let i = 0; i < 10; i++) {
                manColors.push({
                    type: 'linear',
                    x: 0,
                    x2: 0,
                    y: 0,
                    y2: 1,
                    colorStops: [
                        {
                            offset: 0,
                            color: '#6FCAF9', // 最左边
                        },
                        {
                            offset: 0.5,
                            color: '#69B5F4', // 左边的右边 颜色
                        },
                        {
                            offset: 0.5,
                            color: '#4D7DB5', // 右边的左边 颜色
                        },
                        {
                            offset: 1,
                            color: '#6AB8F9',
                        },
                    ],
                });
                womanColors.push({
                    type: 'linear',
                    x: 0,
                    x2: 0,
                    y: 0,
                    y2: 1,
                    colorStops: [
                        {
                            offset: 0,
                            color: '#6CE6C5', // 最左边
                        },
                        {
                            offset: 0.5,
                            color: '#6EE7C6', // 左边的右边 颜色
                        },
                        {
                            offset: 0.5,
                            color: '#5AC1A7', // 右边的左边 颜色
                        },
                        {
                            offset: 1,
                            color: '#61CDB1',
                        },
                    ],
                });
            }
            let option = {
                // backgroundColor: '#010d3a',
                //提示框
                tooltip: {
                    trigger: 'axis',
                    confine:true,
                    formatter: function (e) {
                        // console.log(e);
                        var str =
                            e[0].axisValue +
                            "<br>" +
                            "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
                            e[0].color.colorStops[0].color +
                            ";'></span>" +
                            "" +
                            e[0].seriesName +
                            " : " +
                            e[0].value +
                            "(%)<br>" +
                            "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
                            e[3].color.colorStops[0].color +
                            ";'></span>" +
                            "" +
                            e[3].seriesName +
                            " : " +
                            e[3].value +
                            "(%)";
                        return str;
                    },
                    axisPointer: {
                        // 坐标轴指示器,坐标轴触发有效
                        type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
                    },
                },
                // 图例
                legend: {
                //legend自己调位置,不想展示就设置show:false
                    show: true,
                    itemGap: 20,
                    top: 20,
                    right: '10%',
                    // itemWidth: 14,
                    itemHeight: 14,
                    selectedMode: false,
                    data: [
                        {
                            name: '计划完成量',
                            icon: 'roundRect',
                            itemStyle: {
                                 color: '#02E4FF',
                            },
                        },
                        {
                            name: '实际完成量',
                            icon: 'roundRect',
                            itemStyle: {
                                color: '#02E4FF',
                            },
                        },
                    ],
                    textStyle: {
                        color: '#fff',
                    },
                },
                /**区域位置*/
                grid: {
                    left: '14%',
                    right: '10%',
                    top: '0',
                    bottom: '16%',
                },
                //X轴
                yAxis: {
                    data: xData,
                    type: 'category',
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: "#D1D2D5",
                        },
                    },
                    splitLine: {
                        show: false,
                        lineStyle: {
                            color: "rgba(135,140,147,1)", //左侧显示线
                        },
                    },
                    axisTick: {
                        show: false,
                    },
                    axisLabel: {
                        show: true,
                        // formatter: "{value}%",
                        textStyle: {
                            color: "#A5A5A6",
                            fontSize: 12,
                        },
                    },
                },
                xAxis: {
                    show: true,
                    splitNumber: 4,
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: "#D1D2D5",
                        },
                    },
                    axisTick: {
                        show: false,
                    },
                    splitLine: {
                        show:false
                    },
                    axisLabel: {
                        show:true,
                        formatter: "{value}%",
                        // interval: 0,
                        // rotate: 40,
                        textStyle: {
                            fontFamily: "Microsoft YaHei",
                            color: "#A7A7A8", // x轴颜色
                            fontWeight: "normal",
                            fontSize: "12",
                            lineHeight: 22,
                        },
                        interval: 0, //标签设置为全部显示
                        margin: 15,
                        lineHeight: 15,
                    }
                },
                series: [
                    {
                        name: '计划完成量',
                        type: 'bar',
                        barWidth: barWidth,
                        itemStyle: {
                            normal: {
                                color: function (params) {
                                    return manColors[params.dataIndex % 7];
                                },
                            },
                        },
                        data: manNumber,
                    },
                    {
                        z: 2,
                        type: 'pictorialBar',
                        data: manNumber,
                        symbol: 'diamond',
                        symbolOffset: ['-50%', '-60%'],
                        symbolSize: [barWidth * 0.5, barWidth],
                        itemStyle: {
                            normal: {
                                color: function (params) {
                                    return manColors[params.dataIndex % 7];
                                },
                            },
                        },
                    },
                    {
                        z: 3,
                        type: 'pictorialBar',
                        symbolPosition: 'end',
                        data: manNumber,
                        symbol: 'diamond',
                        symbolOffset: ['50%', '-60%'],
                        symbolSize: [barWidth * 0.5, barWidth],
                        itemStyle: {
                            normal: {
                                borderWidth: 0,
                                color: '#72E0FB',
                            },
                        },
                    },
                    // ---------------------分割线---------------------
                    {
                        name: '实际完成量',
                        type: 'bar',
                        barWidth: barWidth,
                        itemStyle: {
                            normal: {
                                color: function (params) {
                                    return womanColors[params.dataIndex % 7];
                                },
                            },
                        },
                        data: womanNumber,
                    },
                    {
                        z: 2,
                        type: 'pictorialBar',
                        data: womanNumber,
                        symbol: 'diamond',
                        symbolOffset: ['-50%', '60%'],
                        symbolSize: [barWidth * 0.5, barWidth],
                        itemStyle: {
                            normal: {
                                color: function (params) {
                                    return womanColors[params.dataIndex % 7];
                                },
                            },
                        },
                    },
                    {
                        z: 3,
                        type: 'pictorialBar',
                        symbolPosition: 'end',
                        data: womanNumber,
                        symbol: 'diamond',
                        symbolOffset: ['50%', '60%'],
                        symbolSize: [barWidth * 0.5, barWidth],
                        itemStyle: {
                            normal: {
                                borderWidth: 0,
                                color: "#8CF4DD",
                            },
                        },
                    },
                ],
            };
        },

ok,简单粗暴完事,legend和echarts的位置自己去调整就好了,因为实际应用的时候,我是隐藏legend的,没有用上

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ECharts 是一个基于 JavaScript 的开源可视化库,支持多种类型的图表,包括 3D 柱形图。而 Liquidfill 则是 ECharts 中的一个插件,可以用来创建水球图,即圆形的图表,同时支持动画效果。 要创建一个 3D 柱形图,需要在 ECharts 中引入 echarts-gl(ECharts 的 WebGL 渲染扩展库)和 echarts-liquidfill 插件。代码示例: ```js // 引入所需的模块 import * as echarts from 'echarts'; import 'echarts-gl'; import 'echarts-liquidfill'; // 初始化 ECharts 实例 const chart = echarts.init(document.getElementById('chart')); // 定义数据 const data = [ { name: 'A', value: [0, 0, 5] }, { name: 'B', value: [1, 0, 6] }, { name: 'C', value: [2, 0, 8] }, { name: 'D', value: [0, 1, 7] }, { name: 'E', value: [1, 1, 2] }, { name: 'F', value: [2, 1, 9] }, { name: 'G', value: [0, 2, 3] }, { name: 'H', value: [1, 2, 1] }, { name: 'I', value: [2, 2, 4] }, ]; // 定义配置项 const option = { grid3D: {}, xAxis3D: { type: 'category', data: ['X', 'Y', 'Z'], }, yAxis3D: { type: 'category', data: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'], }, zAxis3D: {}, series: [{ type: 'bar3D', data: data.map(item => ({ value: item.value.concat(item.value[2]), itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#00aaff', }, { offset: 1, color: '#00ffaa', }]), }, })), shading: 'color', barSize: 1, opacity: 0.8, }, { type: 'liquidFill', data: data.map(item => ({ value: item.value[2] / 10, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#00aaff', }, { offset: 1, color: '#00ffaa', }]), }, })), shape: 'circle', label: { show: true, fontSize: 16, color: '#fff', formatter: '{b}', }, }], }; // 使用配置项生成图表 chart.setOption(option); ``` 上述代码中,`data` 数组定义了每个柱形图的名称和坐标位置,`option` 对象则定义了图表的配置项。其中,`grid3D`、`xAxis3D`、`yAxis3D` 和 `zAxis3D` 用于定义 3D 坐标系,`series` 则用于定义 3D 柱形图和水球图。柱形图的样式可以通过 `itemStyle` 属性进行设置,而水球图则可以通过 `liquidFill` 类型的系列来创建。 最后,使用 `setOption` 方法将配置项传入,即可在页面中生成 3D 柱形图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值