echarts篇V——立体柱形图

图表特点及问题:

1.柱形图混合折线图

2.柱形图为长方体立体图

在网上查找一番之后,基本上有个思路方向:立方体为三个柱形拼接成的,三个图要使用同一个name

缺陷:肯定是有的,比如第一个柱形图浮在中间菱形图的上面,导致出现比较奇怪的立体图

配置如下:

var indictedCase = [10, 7, 15, 8, 6, 2, 1, 3,5,8,9];
var option = {
    backgroundColor: '#051c71',
    tooltip: {
        trigger: "axis",
        backgroundColor: 'rgb(11,11,81)',
        padding: [15,30],
        extraCssText: 'box-shadow: 0px 0px 25px 5px rgb(41, 95, 159) inset;border-radius:10px'
    },
    legend: {
        show: true,
        top: '5%',
        textStyle: {
            color: "#fff"
        },
        data: ["数量", "金额1", "金额2"]
   },
   grid: {
      top: '20%',
      left: "3%",
      right: "4%",
      bottom: "2%",
      containLabel: true
   },
   xAxis: {
  	    type: "category",
      	axisTick: {
      		show: false
      	},
      	axisLabel: {
      		//"rotate": 30,
      		interval: 0,
      		color: '#eee',
      		fontSize: 14
      	},
      	axisLine: {
      		lineStyle: {
      			color: "#5475c8"
      		}
      	},
      	data: ["2011年", "2012年", "2013年", "2014年", "2015年", "2016年", "2017年", "2018年", "2019年", "2020年", "2021年"]
   },
   yAxis: [{
      	type: "value",
      	name: "单位:(个)",
      	min: 0,
      	// "max": leftMax*2,
      	axisTick: {
      		show: false
      	},
      	splitLine: {
      	    show: false,
           lineStyle: {
               color: 'transparent'
           }  
      	},
      	splitNumber: 5,
      	axisLabel: {
      		show: true,
      		textStyle: {
      			color: "#eee"
      		}
      	},
      	nameTextStyle: {
      		color: "#fff"
      	},
      	axisLine: {
      		lineStyle: {
      			color: "#5475c8"
      		}
      	}
   }, {
      	type: "value",
      	name: "金额:(元)",
      	min: 0,
      	// "max": 15000,
      	axisTick: {
      		show: false
      	},
      	splitLine: {
           lineStyle: {
               color: 'rgba(255,255,255,0.2)'
           }  
      	},
      	splitNumber: 5,
      	axisLabel: {
      		show: true,
      		textStyle: {
      			color: "#eee"
      		}
      	},
      	nameTextStyle: {
      		color: "#fff"
      	},
      	axisLine: {
      		lineStyle: {
      			color: "#5475c8"
      		}
      	}
   }],
   series: [{
      	name: "数量",
      	type: "bar",
      	barWidth: 8,
      	barGap: 0,
      	label: {
      		normal: {
      			show: false,
      			position: "insideRight"
      		}
      	},
      	itemStyle: {
      		normal: {
      			color: "#77f9ef"
      		}
      	},
      	data: indictedCase
   },{
      	name: "数量",
      	type: "bar",
      	barWidth: 8,
      	tooltip: {
      	    show: false
      	},
      	label: {
      		normal: {
      			show: false,
      			position: "insideRight"
      		}
      	},
      	itemStyle: {
      		normal: {
      			color: "#52bbb3"
      		}
      	},
      	data: indictedCase
   },{
      	name: "数量",
      	type: "pictorialBar", // 长方体顶部四边形
        symbol: 'diamond',
        symbolRotate:0,
        symbolSize: ['16','10'],
        symbolOffset:['0','-5'],
        symbolPosition: 'end',
        z: 3, // 顶部四边形
      	tooltip: {
      	    show: false
      	},
      	label: {
      		normal: {
      			show: false,
      			position: "insideRight"
      		}
      	},
      	itemStyle: {
      		normal: {
      			color: "#52bbb3"
      		}
      	},
      	data: indictedCase
   }, {
      	name: "金额1",
      	type: "line",
      	yAxisIndex: 1,
      	showAllSymbol: true,
      	symbol: "circle",
      	symbolSize: 10,
      	smooth: true,
      	itemStyle: {
      		color: "rgb(253,146,166)"
      	},
      	lineStyle: {
      		color: "rgb(253,146,166)"
      	},
      	data: [1000,1200,1500,1800,1700,1900,2000,2500,1500,1770,1300]
   },{
      	name: "金额2",
      	type: "line",
      	yAxisIndex: 1,
      	showAllSymbol: true,
      	symbol: "circle",
      	symbolSize: 10,
      	smooth: true,
      	itemStyle: {
      		color: "rgb(78,230,244)"
      	},
      	lineStyle: {
      		color: "rgb(78,230,244)"
      	},
      	data: [900,1000,1300,1700,1600,1900,1500,2100,2000,1500,1100]
   }]
};

效果如下:

如果有小伙伴解决了这个角的问题,或者有好的解决方案,一起来讨论啊~

 

补:按照评论区小伙伴的指导,z属性即可解决顶部小角的问题,已补充。

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ECharts 是一个基于 JavaScript 的开源可视化库,它可以用于制作各种类型的图表,包括立体柱形图立体柱形图是一种三维图表,它可以展示数据在三个方向上的变化情况,通过不同的高度来表示数据的大小。 在 ECharts 中制作立体柱形图,需要使用柱形图和三维坐标系两个组件。柱形图组件用于绘制柱形,而三维坐标系组件则负责展示立体效果。 下面是一个简单的立体柱形图的配置示例: ``` option = { tooltip: {}, visualMap: { max: 20, inRange: { color: ['#50a3ba', '#eac736', '#d94e5d'] } }, xAxis3D: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] }, yAxis3D: { type: 'value' }, zAxis3D: { type: 'category', data: ['2019', '2020', '2021'] }, grid3D: { boxWidth: 200, boxDepth: 80, viewControl: { distance: 300 }, light: { main: { intensity: 1.2, shadow: true }, ambient: { intensity: 0.3 } } }, series: [{ type: 'bar3D', data: [ ['A', 0, '2019', 10], ['B', 1, '2019', 15], ['C', 2, '2019', 13], ['D', 3, '2019', 17], ['E', 4, '2019', 12], ['A', 0, '2020', 7], ['B', 1, '2020', 9], ['C', 2, '2020', 11], ['D', 3, '2020', 15], ['E', 4, '2020', 8], ['A', 0, '2021', 12], ['B', 1, '2021', 8], ['C', 2, '2021', 14], ['D', 3, '2021', 10], ['E', 4, '2021', 15] ], shading: 'lambert', label: { textStyle: { fontSize: 16, borderWidth: 1 } }, itemStyle: { opacity: 0.8 } }] }; ``` 以上代码中,我们定义了一个三维坐标系和一个柱形图柱形图的数据包括横轴、纵轴和高度,通过 series.type 属性指定为 bar3D 类型。grid3D 中定义了一些参数用于控制立体效果的显示,包括箱子的宽度和深度,视角距离和光照等。在页面中引入 echarts.min.js 文件后,可以通过调用 echarts.init() 方法和 setOption() 方法将配置应用到图表中。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值