echarts3d柱状图

echarts柱状图模拟立体效果

// 3d柱状图
stereobar('ck_left_bottom_bar', rmhytop5n, rmhytop5v)
function stereobar(id, name, value) {
    var myChart = echarts.init(document.getElementById(id), null, { renderer: 'svg' });
    // 指定图表的配置项和数据 
    var option = {
        tooltip: {
            trigger: 'axis',
            confine: true,
            axisPointer: { type: 'none' },
            textStyle: { fontSize: 12, fontWeight: 500 },
            formatter(params) {
                // 只展示柱子对应的内容,把顶部底部的 tooltip 过滤掉
                return params.reduce((pre, i) => {
                    if (i.componentSubType === 'bar') {
                        i.marker = i.marker.replace(/\[object Object\]/, i.color.colorStops[1].color);
                        i.value = `<span style="flex: 1; text-align: right; margin-left: 1rem;">${i.value}</span>`;
                        const current = `<div style="display: flex; align-items: center; height: 1.6rem;">${i.marker}${i.seriesName} ${i.value}</div>`;
                        return `${pre}${current}${i.axisValue}`;
                    }
                    return pre;
                }, '');
            },
        },
        grid: {
            left: '10%',
            right: '10%',
            bottom: '15%',
            top: '15%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            data: name,
            nameTextStyle: {
                color: "#fff"
            },
            axisLine: {
                show: false,
                lineStyle: {
                    color: "#fff",
                    opacity: 0.18
                }
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                formatter: function(value, index) {
                    if (value.length > 3) {
                        return value.substr(0, 2) + '...'
                    } else {
                        return value
                    }
                }
            }
        },
        yAxis: {
            type: 'value',
            // name: "人数",
            nameTextStyle: {
                color: "#fff"
            },
            lineStyle: {
                show: false
            },
            axisLabel: {
                show: false,
                textStyle: {
                    color: '#fff',
                }
            },
            axisTick: {
                show: false
            },
            splitLine: {
                show: false,
                //  改变轴线颜色
                lineStyle: {
                    // 使用深浅的间隔色
                    color: "#41ABFF",
                    opacity: 0.18
                }
            },
            axisLine: {
                show: false
            }
        },
        series: [{
                name: '今日已反馈人数',
                type: 'bar',
                barWidth: 15,
                stack: '1',
                barCategoryGap: 12,
                data: value,
                color: '#fff',
                itemStyle: { // 柱体渐变色
                    color: {
                        type: 'linear',
                        x: 0,
                        x2: 1,
                        y: 0,
                        y2: 0,
                        colorStops: [
                            { offset: 0, color: 'rgba(1, 180, 255, 0.7)' },
                            { offset: 0.5, color: 'rgba(1, 180, 255, 0.7)' },
                            { offset: 0.5, color: 'rgba(1, 180, 255, 0.3)' },
                            { offset: 1, color: 'rgba(1, 180, 255, 0.3)' }
                        ]
                    },
                    shadowColor: 'rgba(37, 179, 208, 0.6)',
                    shadowBlur: 10
                },

            },
            {
                name: '今日已反馈人数',
                type: 'pictorialBar',
                symbolSize: [15, 15],
                symbol: 'diamond',
                // 这个属性很重要,直接决定了顶部跟柱子是否契合
                symbolOffset: [0, -8],
                z: 12,
                itemStyle: { color: 'rgba(1, 180, 255, 1)' },
                symbolPosition: 'end',
                data: value,
                label: {
                    show: true,
                    position: 'top',
                    color: '#fff'
                },
            },

        ],
    }
    myChart.setOption(option);
    window.addEventListener('resize', function() {
        myChart.resize();
    });
};

以此记录
效果图如下:
在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ECharts 是一个由百度开发的数据可视化库,它提供了丰富而强大的表功能,包括 3D。要绘制一个 ECharts 3D,你可以按照以下步骤进行操作: 1. 首先,确保你已经引入了 ECharts 库。你可以在 HTML 文件中使用以下代码来引入 ECharts: ```html <script src="https://cdn.jsdelivr.net/npm/echarts@5.1.2/dist/echarts.min.js"></script> ``` 2. 创建一个具有指定宽度和高度的 DOM 元素,用于容纳表。例如: ```html <div id="chart" style="width: 600px; height: 400px;"></div> ``` 3. 使用 JavaScript 代码初始化并配置表。以下是一个简单的示例: ```javascript // 获取容器元素 var chartContainer = document.getElementById('chart'); // 初始化表 var chart = echarts.init(chartContainer); // 配置项 var options = { grid3D: {}, // 开启 3D 网格 xAxis3D: {}, // x 轴配置 yAxis3D: {}, // y 轴配置 zAxis3D: {}, // z 轴配置 series: [{ type: 'bar3D', // 使用 3D类型 data: [[0, 0, 0, 1]], // 数据数组,每个数据项格式为 [x, y, z, value] shading: 'lambert', // 光照渲染模式 label: { show: true, // 显示柱上的标签 textStyle: { fontSize: 16, // 标签字体大小 } }, itemStyle: { opacity: 0.8, // 柱透明度 color: '#ff0000' // 柱颜色 } }] }; // 使用配置项生成表 chart.setOption(options); ``` 这是一个简单的示例,你可以根据你的需求进行进一步的配置和样式调整。通过修改 `data` 数组中的数据,你可以绘制更多的柱
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值