chart.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. const option01 = {
  2. color: ["#2f89cf"],
  3. tooltip: {
  4. trigger: "axis",
  5. axisPointer: {
  6. // 坐标轴指示器,坐标轴触发有效
  7. type: "shadow" // 默认为直线,可选为:'line' | 'shadow'
  8. }
  9. },
  10. grid: {
  11. left: "10",
  12. top: "30",
  13. right: "10",
  14. bottom: "5",
  15. containLabel: true
  16. },
  17. xAxis: [{
  18. type: "category",
  19. data: [],
  20. axisTick: {
  21. alignWithLabel: true
  22. },
  23. axisLabel: {
  24. textStyle: {
  25. color: "rgba(255,255,255,.6)",
  26. fontSize: "12"
  27. }
  28. },
  29. axisLine: {
  30. show: false
  31. }
  32. }],
  33. yAxis: [{
  34. type: "value",
  35. name: 'kg',
  36. nameTextStyle: {
  37. color: "rgba(255,255,255,.6)"
  38. },
  39. axisLabel: {
  40. textStyle: {
  41. color: "rgba(255,255,255,.6)",
  42. fontSize: "12"
  43. }
  44. },
  45. axisLine: {
  46. lineStyle: {
  47. color: "rgba(255,255,255,.1)"
  48. // width: 1,
  49. // type: "solid"
  50. }
  51. },
  52. splitLine: {
  53. lineStyle: {
  54. color: "rgba(255,255,255,.1)"
  55. }
  56. }
  57. }],
  58. series: [{
  59. name: "产量",
  60. type: "bar",
  61. barWidth: "12",
  62. data: [],
  63. itemStyle: {
  64. normal: {
  65. barBorderRadius: 30,
  66. color: {
  67. type: 'linear',
  68. x: 0,
  69. y: 0,
  70. x2: 0,
  71. y2: 1,
  72. colorStops: [{
  73. offset: 0,
  74. color: '#3bedcb' // 0% 处的颜色
  75. }, {
  76. offset: 1,
  77. color: '#086ce6' // 100% 处的颜色
  78. }],
  79. global: false // 缺省为 false
  80. },
  81. },
  82. },
  83. }]
  84. };
  85. let colors = ['#f21c1c', '#f85d00', '#fd8b0e', '#fcbe2b']
  86. function optionFun(arrName,arrValue) {
  87. console.log(arrName)
  88. console.log(arrValue)
  89. return {
  90. yAxis: [{
  91. type: 'category',
  92. inverse: true,
  93. axisLine: {
  94. show: false //坐标线
  95. },
  96. axisTick: {
  97. show: false //小横线
  98. },
  99. axisLabel: {
  100. color: '#49b0db',
  101. fontSize: 13
  102. },
  103. data: arrName
  104. }, {
  105. type: 'category',
  106. inverse: true,
  107. axisTick: 'none',
  108. axisLine: 'none',
  109. show: true,
  110. axisLabel: {
  111. textStyle: {
  112. fontSize: '13'
  113. },
  114. },
  115. data: arrValue.map((value, index) => {
  116. return {
  117. value,
  118. textStyle: {
  119. color: colors[index]
  120. }
  121. }
  122. })
  123. }],
  124. xAxis: {
  125. show: false,
  126. },
  127. tooltip: {
  128. trigger: 'axis',
  129. axisPointer: {
  130. type: 'none'
  131. },
  132. formatter: function (params) {
  133. return params[0].name + ' : ' + params[0].value
  134. }
  135. },
  136. grid: {
  137. top: '40',
  138. right: '50',
  139. left: '80',
  140. bottom: '40' //图表尺寸大小
  141. },
  142. series: [{
  143. type: 'bar',
  144. barWidth: '10px',
  145. showBackground: true,
  146. backgroundStyle: {
  147. color: 'rgba(26, 34, 96, 1)',
  148. barBorderRadius: [30, 30, 30, 30] //圆角大小
  149. },
  150. itemStyle: {
  151. normal: {
  152. color: (params) => {
  153. return colors[params.dataIndex]
  154. }, //每个数据的颜色
  155. barBorderRadius: [30, 30, 30, 30], //圆角大小
  156. shadowBlur: 10,
  157. shadowColor: 'rgba(0, 103, 255, 0.2)',
  158. shadowOffsetX: -5,
  159. shadowOffsetY: 5,
  160. },
  161. },
  162. data:arrValue
  163. }]
  164. }
  165. }
  166. export {
  167. option01,
  168. optionFun
  169. }