• echarts 双向柱状图 共用y轴


     

     效果图如下:

     

    代码:

    1. const animationDuration = 1500
    2. const barName = ['销售管理部', '生产技术部', '研发部', '质量管理部', '总经办', '采购供应部', '人力资源部', '综合管理部', '财务部']
    3. const rzData= [34, 26, 17, 17, 4, 4, 4, 4, 2]
    4. const lzData= [34, 26, 17, 17, 4, 4, 4, 4, 2]
    5. this.chart.setOption({
    6. color: ['#2ec7c9', '#ED7D31', '#5ab1ef'],
    7. tooltip: {
    8. trigger: 'axis',
    9. axisPointer: {
    10. type: 'shadow'
    11. }
    12. },
    13. legend: {
    14. left: 'center',
    15. top: '0',
    16. },
    17. grid: [
    18. {
    19. show: false,
    20. left: '3%',
    21. top: '30',
    22. bottom: '0%',
    23. containLabel: true,
    24. width: '38%'
    25. },
    26. {
    27. show: false,
    28. left: '51.5%',
    29. top: '30',
    30. bottom: '6%',
    31. width: '0%'
    32. },
    33. {
    34. show: false,
    35. right: '3%',
    36. top: '30',
    37. bottom: '0%',
    38. containLabel: true,
    39. width: '38%'
    40. }
    41. ],
    42. xAxis: [
    43. {
    44. name: '人数',
    45. type: 'value',
    46. inverse: true, // 强制设置坐标轴分割间隔
    47. axisLine: {
    48. // 坐标轴轴线相关设置
    49. show: true, // 是否显示坐标轴轴线
    50. onZero: true, // X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上
    51. lineStyle: {
    52. color: '#ECEDF0'
    53. }
    54. },
    55. axisTick: {
    56. show: true
    57. },
    58. position: 'bottom',
    59. axisLabel: {
    60. show: true,
    61. color: '#c6d3d7',
    62. fontSize: 12,
    63. fontFamily: 'DINPro-Regular'
    64. },
    65. splitLine: {
    66. show: false
    67. }
    68. },
    69. {
    70. gridIndex: 1,
    71. show: false
    72. },
    73. {
    74. gridIndex: 2,
    75. axisLine: {
    76. show: true, // 是否显示坐标轴轴线
    77. onZero: true, // X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上
    78. lineStyle: {
    79. color: '#ECEDF0'
    80. }
    81. },
    82. axisTick: {
    83. show: true
    84. },
    85. position: 'bottom',
    86. axisLabel: {
    87. show: true,
    88. color: '#c6d3d7',
    89. fontSize: 12,
    90. fontFamily: 'DINPro-Regular'
    91. },
    92. splitLine: {
    93. show: false
    94. }
    95. }
    96. ],
    97. yAxis: [
    98. {
    99. type: 'category',
    100. inverse: true,
    101. position: 'right',
    102. axisLine: {
    103. show: true,
    104. lineStyle: {
    105. color: '#606266'
    106. }
    107. },
    108. axisTick: {
    109. show: false
    110. },
    111. axisLabel: {
    112. show: false
    113. },
    114. data: barName
    115. },
    116. {
    117. gridIndex: 1,
    118. type: 'category',
    119. inverse: true,
    120. position: 'left',
    121. axisLine: {
    122. show: false
    123. },
    124. axisTick: {
    125. show: false
    126. },
    127. axisLabel: {
    128. show: true,
    129. textStyle: {
    130. color: '#606266',
    131. fontSize: 12,
    132. fontFamily: 'pmzd_title'
    133. },
    134. align: 'center'
    135. },
    136. data: barName.map(function(value) {
    137. return {
    138. value: value,
    139. textStyle: {
    140. align: 'center'
    141. }
    142. }
    143. })
    144. },
    145. {
    146. gridIndex: 2,
    147. type: 'category',
    148. inverse: true,
    149. position: 'left',
    150. axisLine: {
    151. show: true,
    152. lineStyle: {
    153. color: '#606266'
    154. }
    155. },
    156. axisTick: {
    157. show: false
    158. },
    159. axisLabel: {
    160. show: false
    161. },
    162. data: barName
    163. }
    164. ],
    165. series: [
    166. {
    167. name: '入职',
    168. type: 'bar',
    169. itemStyle: {
    170. normal: {
    171. label: {
    172. show: true, // 开启显示
    173. position: 'left', // 在上方显示
    174. textStyle: {
    175. // 数值样式
    176. // color: colors[0].borderColor,
    177. color: '#606266',
    178. fontSize: 12
    179. }
    180. },
    181. borderWidth: 1
    182. }
    183. },
    184. data: rzData,
    185. animationDuration
    186. },
    187. {
    188. name: '离职',
    189. type: 'bar',
    190. xAxisIndex: 2,
    191. yAxisIndex: 2,
    192. itemStyle: {
    193. normal: {
    194. label: {
    195. show: true, // 开启显示
    196. position: 'right', // 在上方显示
    197. textStyle: {
    198. // 数值样式
    199. color: '#606266',
    200. fontSize: 12
    201. },
    202. },
    203. borderWidth: 1
    204. }
    205. },
    206. data: lzData,
    207. animationDuration
    208. }
    209. ]
    210. })

  • 相关阅读:
    1056 Mice and Rice
    分布式事务之BASE理论
    搞定Python常用的数据结构
    Django 访问静态文件的APP staticfiles
    在React项目中引入字体文件并使用
    【深入理解java虚拟机】 - JVM字节码指令介绍
    Linux shell编程学习笔记11:关系运算
    Nginx基本知识
    flex布局入门讲解
    C++对象实例创建实验
  • 原文地址:https://blog.csdn.net/zhufan2333/article/details/133945395