Echarts自定义样式实现3D柱状图-长方体-圆柱体,两种样式
效果图
长方体
柱状体
代码
DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
<meta charset="utf-8">
<title>3D柱状图-圆柱体title>
head>
<body style="height: 100%; margin: 0">
<div id="main" style="height: 100%">div>
<script type="text/javascript" src="https://cdn.staticfile.org/jquery/3.7.1/jquery.min.js">script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js">script>
<script type="text/javascript">
initData(['周一', '周二', '周三', '周四', '周五', '周六'], [100, 50, 70, 80, 60, 40])
function initData(xData, yData) {
var chartDom = document.getElementById('main');
var bar = echarts.init(chartDom);
let options = {
grid: {
left: 50,
top: 50,
right: 50,
bottom: 50
},
tooltip: {},
legend: {
textStyle: {
color: '#999'
}
},
xAxis: {
data: [],
axisLine: {
show: true
},
axisLabel: {
color: '#999',
rotate: 0
},
axisTick: {
show: false
}
},
yAxis: {
axisLine: {
show: true
},
axisLabel: {
color: '#999',
},
axisTick: {
show: false
},
splitLine: {
show: false
}
},
series: []
}
let symbolData = [], newShadowHight = [];
let heights = 0;
yData.forEach(item => {
symbolData.push(1)
heights += item
});
newShadowHight = yData.map(item => heights);
options.xAxis.data = xData;
options.series = [
{
z: 2,
type: 'pictorialBar',
symbol: 'circle',
symbolOffset: ['0%', '50%'],
symbolSize: [30, 12],
toolltip: {
show: false
},
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0, color: '#1f7eff'}, {
offset: 1,
color: '#64adff'
}])
},
data: symbolData,
},
{
z: 1,
type: 'bar',
barWidth: 30,
data: yData
},
{
z: 3,
type: 'pictorialBar',
symbol: 'circle',
symbolPosition: 'end',
symbolOffset: ['0%', '-50%'],
symbolSize: [30, 12],
toolltip: {
show: false,
},
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0, color: '#1f7eff'}, {
offset: 1,
color: '#64adff',
}])
},
data: yData,
},
];
bar.setOption(options);
window.addEventListener('resize', bar.resize);
}
script>
body>
html>
series配置项目