Echrts实现立体圆柱体 柱状图

10 篇文章 0 订阅

在这里插入图片描述
就是这种效果,我用的echrts版本是5.4.1
废话不多说,直接上代码(里面代码有注释,我就不再解释了)
1.这个是html代码,我是vue2

<template>
    <div style="display: flex; position: relative">
        <div id="partEcharts" ref="partEcharts" style="width:100%;height:400px;"></div>
    </div>
</template>

2.下面是js代码

<script>
import * as echarts from "echarts";
    export default {
        data() {
            return {
                option:{
                    grid: {
                        left: '5%',
                        right: '5%',
                        top: '10%',
                        bottom: '12%',
                        containLabel: true
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: function (parms) {
                            return parms.marker + " " + parms.name + ":" + parms.value + "%";
                        }
                    },
                    xAxis: {
                        type: 'category', // category(坐标轴类型)
                        data: ['上海', '许昌', '商丘', '北京', '西安', '苏州'],
                        axisTick: { // 坐标轴刻度相关配置
                            show: false // 是否显示坐标轴刻度
                        },
                        label:{
                            show:true
                        },
                        axisLine: { // 坐标轴轴线相关配置
                            lineStyle: { // 坐标轴轴线样式
                                color: 'rgba(255,255,255,0.15)' // 坐标轴轴线颜色
                            }
                        },
                        axisLabel: { // 坐标轴刻度标签相关配置
                            color: '#B7BDBF',
                            fontSize: 14,
                            fontWeight:600
                        }
                    },
                    yAxis: {
                        type: 'value', // value(数值轴,适用于连续数据)
                        name:'单位(%)',
                        nameTextStyle:{
                            color:'#fff',
                            padding:[0,32,10,0],
                        },
                        axisTick: { // 坐标轴刻度相关配置
                            show: false  // 是否显示坐标轴刻度
                        },
                        axisLine: { // 坐标轴轴线相关配置
                            show: false // 是否显示坐标轴轴线
                        },
                        axisLabel: { // 坐标轴刻度标签相关配置
                            color: '#ffffff',
                            fontSize: 14
                        },
                        splitLine: { // 坐标轴在 grid 区域中的分隔线
                            lineStyle: { // 分割线配置
                                color: 'rgba(255,255,255,0.15)' // 分割线颜色
                            }
                        },
                        interval:10,
                    },
                    series: [
                        // 底部的椭圆形(象形柱图):pictorialBar
                        {
                            type: "pictorialBar", // pictorialBar(象形柱图)
                            label: { // 图形上的文本标签,可用于说明图像的一些数据信息,比如值,名称等
                                show: true, //是否显示标签
                                position: [0,-30], // 标签的位置(可以是绝对的像素值或者百分比['50%','50%',也可以是top,left等])
                                formatter:'{c}%',
                                color: '#fff',
                                fontSize: 14,

                            },
                            symbolSize: [16, 8], // 图形的大小用数组分别比表示宽和高,也乐意设置成10相当于[10,10]
                            symbolOffset: [0, 0], // 图形相对于原本位置的偏移
                            z: 12, // 象形柱状图组件的所有图形的 z 值.控制图形的前后顺序.z 值小的图形会被 z 值大的图形覆盖.
                            itemStyle: { // 图形样式
                                // echarts.graphic.LinearGradient(echarts内置的渐变色生成器)
                                // 4个参数用于配置渐变色的起止位置,这4个参数依次对应右 下 左 上
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                    // 这里 offset: 0 1 ,表示从下往上的渐变色
                                    {
                                        offset: 0, // 0%处的颜色
                                        color: "rgba(31,97,234,0.8)"
                                    },
                                    {
                                        offset: 1, // 100%处的颜色
                                        color: "rgba(31,97,234,0.8)"
                                    }
                                ])
                            },
                            data: [78, 85, 78, 99, 67, 53],
                        },
                        // 中间的长方形柱状图(柱状图):bar
                        {
                            type: 'bar', // 柱状图
                            barWidth: 16, // 柱条的宽度,不设时自适应
                            barGap: '0%', // 柱子与柱子之间的距离
                            itemStyle: { // 图形样式
                                // color支持(rgb(255,255,255)、rgba(255,255,255,1)、#fff,也支持渐变色和纹理填充)
                                // 下面就是使用线性渐变
                                color: {
                                    "x": 0,
                                    "y": 0,
                                    "x2": 0,
                                    "y2": 1,
                                    "type": "linear",
                                    "global": false,
                                    "colorStops": [{
                                        "offset": 0, // 0%处的颜色
                                        "color": "rgba(0,183,255,1.000)"
                                    }, {
                                        "offset": 1, // 100%处的颜色
                                        "color": "rgba(34,68,172,0.35)"
                                    }]
                                }
                            },
                            data: [78, 85, 78, 99, 67, 53]
                        },
                        // 顶部的椭圆形(象形柱图):pictorialBar
                        {
                            type: "pictorialBar",
                            symbolSize: [16, 10],
                            symbolOffset: [0, -5],
                            z: 12,
                            symbolPosition: "end",
                            itemStyle: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                    {
                                        offset: 0,
                                        color: "rgba(33,243,255,1)"
                                    },
                                    {
                                        offset: 1,
                                        color: "rgba(33,243,255,1)"
                                    }
                                ], false)
                            },
                            data: [78, 85, 78, 99, 67, 53]
                        },
                        {
                            type: 'line', // 折线图
                            smooth: false, // 是否平滑曲线显示
                            showSymbol:true, //是否显示折线上的点
                            symbol:'circle',
                            symbolSize:6,
                            itemStyle:{
                                color:'#5FEEF1',
                                borderWidth:6,
                                borderColor:'rgba(23,224,253,0.29)'
                            },
                            lineStyle: {
                                color: '#37D8DC',
                                width: 1,
                            },
                            data: [90, 80, 78, 100, 67, 5]
                        }
                    ]
                }
            }
        },
        mounted(){
            let mycharts = echarts.init(this.$refs.partEcharts);
            mycharts.clear();
            echarts.registerTheme('myTheme', {
                itemStyle: this.itemStyle
            }); // 注册主题
            mycharts.setOption(this.option,'myTheme');
        }
    }
</script>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Echarts 是一个非常流行的数据可视化库,支持多种图表类型。在 Echarts 中,3D 圆柱柱状图可以使用柱状图(bar)系列,同时设置 3D 属性即可实现。 以下是一个简单的示例代码: ```javascript // 初始化echarts实例 var myChart = echarts.init(document.getElementById('myChart')); // 指定图表的配置项和数据 var option = { tooltip: {}, visualMap: { show: false, dimension: 2, min: 0, max: 100, inRange: { color: ['#d94e5d','#eac736','#50a3ba'].reverse() } }, xAxis3D: { type: 'category', data: ['Apple', 'Samsung', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo'] }, yAxis3D: { type: 'value' }, zAxis3D: { type: 'category', data: ['Q1', 'Q2', 'Q3', 'Q4'] }, grid3D: { boxWidth: 200, boxDepth: 80, light: { main: { intensity: 1.2 }, ambient: { intensity: 0.3 } } }, series: [{ type: 'bar3D', data: [ [0, 0, 78], [1, 0, 60], [2, 0, 85], [3, 0, 93], [4, 0, 82], [5, 0, 86], [0, 1, 58], [1, 1, 75], [2, 1, 86], [3, 1, 69], [4, 1, 91], [5, 1, 92], [0, 2, 88], [1, 2, 76], [2, 2, 67], [3, 2, 78], [4, 2, 93], [5, 2, 92], [0, 3, 92], [1, 3, 79], [2, 3, 88], [3, 3, 93], [4, 3, 81], [5, 3, 76] ], shading: 'lambert', label: { show: true, textStyle: { fontSize: 16, borderWidth: 1 } }, itemStyle: { opacity: 0.8 } }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); ``` 在这段代码中,我们使用了 Echarts 的 bar3D 系列,通过设置 x、y、z 轴数据来创建 3D 圆柱柱状图。同时,我们还设置了 grid3D 属性,来控制图表的 3D 效果。 以上是一个简单的实现,你可以根据自己的需求来设置不同的参数和属性,来达到更好的可视化效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值