全部代碼
< ! DOCTYPE html>
< html lang= "en" style= "height: 100%" >
< head> < meta charset= "utf-8" > < title> 3 D柱狀圖- 圓柱體- 文字豎排< / 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/echarts@5.4.1/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 , label: { normal: { show: true , position: 'inside' , verticalAlign: 'middle' , formatter : function ( params ) { console. log ( params) ; let txtArry = params. name. split ( '' ) ; let rs = "" ; for ( var i = 0 ; i < txtArry. length; i++ ) { rs += txtArry[ i] + "\n" ; } return rs; } , rich: { a: { color: '#fff' , fontSize: 14 , align: 'center' , } , } } } , 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' , } ] ) } , label: { normal: { show: true , position: 'top' , formatter: '{a|{c}萬人}' , rich: { a: { color: 'inherit' , fontSize: 14 , align: 'center' } , } } } , data: yData, } , ] ; bar. setOption ( options) ; window. addEventListener ( 'resize' , bar. resize) ; } < / script>
< / body>
< / html>
效果圖