柱狀圖X軸文字顯示不全


 

                                       解決echarts柱狀圖橫軸文字顯示不全

  在使用echarts圖表框架開發的過程中,當柱狀圖底部X軸文字過長時,將會出現文字顯示不全的問題。

  解決代碼演示:

  

  1 <!-- 為ECharts准備一個具備大小(寬高)的Dom -->
  2     <div id='${id}' style="width:${width}px;height:${height}px"></div>
  3     
  4     <script type="text/javascript">
  5     var dom = document.getElementById('${id}');
  6     var myChart = echarts.init(dom,'macarons');
  7     var app = {};
  8 
  9 
 10 
 11 var option = {
 12     tooltip: {
 13         trigger: 'axis',
 14         axisPointer: {
 15             type: 'cross',
 16             crossStyle: {
 17                 color: '#999'
 18             },
 19             label:{
 20                 default: 2
 21                 }
 22         }
 23     },
 24    toolbox: {
 25         feature: {
 26          // dataView: {show: true, readOnly: false},
 27           //magicType: {show: true, type: ['line', 'bar']},
 28            //restore: {show: true},
 29           //saveAsImage: {show: true}
 30         },
 31         right:'3%'
 32    },
 33     legend: {
 34         left:'2%',
 35         data:['同期銷售金額','銷售金額','同比增長率']
 36     },
 37       grid: { // 控制圖的大小,調整下面這些值就可以,
 38         x: 50,//控制x軸文字與底部的距離
 39          y2: 150 // y2可以控制傾斜的文字獄最右邊的距離,放置傾斜的文字超過顯示區域
 40         },
 41     xAxis: [
 42         {
 43             type: 'category',
 44             data: ${cpx},//['CPS','LS','MD','TD','其他'],
 45             axisPointer: {
 46                 type: 'shadow'
 47             },
 48              axisLabel:{
 49                   interval:0,
 50                   rotate:-45,//傾斜度 -90 至 90 默認為0
 51                   margin:2,
 52                   textStyle:{
 53                    
 54                 fontSize: 9,//橫軸字體大小
 55                     color:"#000000"
 56                   }
 57                 }
 58         }
 59     ],
 60     yAxis: [
 61         {
 62             type: 'value',
 63             name: '金額/百萬',
 64             min: 0,
 65             max: 20,
 66             interval: 4,
 67             splitLine:{show:  true},
 68             axisLabel: {
 69                 formatter: '{value}'
 70             }
 71         },
 72         {
 73             type: 'value',
 74             name: '同比增長率',
 75             min: -20,
 76             max: 100,
 77             interval: 24,
 78             splitLine:{show: true},
 79             axisLabel: {
 80                 formatter: '{value} %'
 81             }
 82         }
 83     ],
 84     series: [
 85         {
 86             name:'同期銷售金額',
 87             type:'bar',
 88              itemStyle:{
 89                                     normal:{
 90                                         color:'#7BC9EA',
 91                                          barBorderRadius: [3, 3, 0, 0],
 92                 },
 93                  //柱形圖圓角,鼠標移上去效果,如果只是一個數字則說明四個參數全部設置為那么多
 94               emphasis: {
 95                           barBorderRadius: 30
 96              }
 97                 
 98                },
 99             data:${xsmb}
100             
101         },
102         {
103             name:'銷售金額',
104             type:'bar',
105             itemStyle:{
106                                     normal:{
107                                         color:'#B194D1',
108                                          barBorderRadius: [3, 3, 0, 0],
109                                     }
110                },
111                
112             data:${xsdc}
113         },
114         {
115             name:'同比增長率',
116             type:'scatter',
117             yAxisIndex: 1,
118 itemStyle:{
119                                     normal:{
120                                         color:'#FDA029'
121                                        
122                                     }
123                },
124             data:${dc} // #FF7256
125         }
126     ]
127 };
128 
129 myChart.setOption(option);
130 </script>

 

 

  效果

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM