chart.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import * as echarts from '../components/ec-canvas/echarts';
  2. const app = getApp();
  3. const scale = app.scale;
  4. export const barChartOptions = ({
  5. legend = [],
  6. xAxis = [],
  7. series = []
  8. }, colors = ['#FFF'], configs = { barWidth: 48 }) => ({
  9. color: ['#FFF'],
  10. tooltip: {
  11. show: false,
  12. trigger: 'axis',
  13. backgroundColor: '#FFFFFF',
  14. textStyle: {
  15. color: '#2596FF',
  16. },
  17. formatter: '用水量: {c0}吨',
  18. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  19. type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
  20. }
  21. },
  22. grid: {
  23. left: 0,
  24. right: Math.round(10 * scale),
  25. bottom: Math.round(70 * scale),
  26. top: Math.round(40 * scale),
  27. containLabel: true
  28. },
  29. xAxis: [
  30. {
  31. type: 'category',
  32. data: xAxis,
  33. axisLabel: {
  34. color: '#FFF',
  35. fontSize: Math.round(22 * scale)
  36. },
  37. axisTick: {
  38. alignWithLabel: true
  39. },
  40. axisLine: {
  41. show: false
  42. },
  43. axisTick: {
  44. show: false
  45. },
  46. splitNumber: 7
  47. }
  48. ],
  49. yAxis: [
  50. {
  51. type: 'value',
  52. axisLabel: {
  53. color: '#FFF',
  54. fontSize: Math.round(22 * scale)
  55. },
  56. axisLine: {
  57. show: false
  58. },
  59. axisTick: {
  60. show: false
  61. },
  62. splitLine: {
  63. lineStyle: {
  64. type: 'dashed',
  65. color: 'rgba(255,255,255,0.6)',
  66. width: 0.5
  67. }
  68. }
  69. }
  70. ],
  71. series: [
  72. {
  73. name: '用水量',
  74. type: 'bar',
  75. barWidth: Math.round(configs.barWidth * scale),
  76. data: series[0],
  77. itemStyle: {
  78. color(params) {
  79. const arr = series[0];
  80. var max = Math.max(...arr);
  81. var min = Math.min(...arr);
  82. const { value } = params;
  83. if (value == max) {
  84. return '#80FDF6';
  85. } else if (value == min) {
  86. return '#A9FFC5';
  87. }
  88. return '#D3ECFF';
  89. },
  90. barBorderRadius: [Math.round(4 * scale), Math.round(4 * scale), 0, 0]
  91. },
  92. label: {
  93. show: true, //开启显示
  94. position: 'top', //在上方显示
  95. distance: 10,
  96. verticalAlign: 'middle',
  97. rotate: 30,
  98. align: 'center',
  99. textStyle: { //数值样式
  100. color(params) {
  101. const arr = series[0];
  102. var max = Math.max(...arr);
  103. var min = Math.min(...arr);
  104. const { value } = params;
  105. if (value == max) {
  106. return '#80FDF6';
  107. } else if (value == min) {
  108. return '#A9FFC5';
  109. }
  110. return '#FFF';
  111. },
  112. fontSize: Math.round(22 * scale)
  113. },
  114. formatter(val) {
  115. return val.data ? val.data : '';
  116. }
  117. }
  118. }
  119. ]
  120. })
  121. export const lineChartOptions = ({
  122. legend = [],
  123. xAxis = [],
  124. series = []
  125. }, colors = ['#FFF']) => ({
  126. color: colors,
  127. tooltip: {
  128. trigger: 'axis',
  129. backgroundColor: '#FFFFFF',
  130. textStyle: {
  131. color: '#2596FF',
  132. },
  133. formatter: '{b0}\n{a}: {c0}吨',
  134. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  135. type: 'line', // 默认为直线,可选为:'line' | 'shadow'
  136. lineStyle : {
  137. color: 'rgba(255, 255, 255, 0.6)',
  138. },
  139. /* label: {
  140. show: true,
  141. color: '#2596FF',
  142. backgroundColor: 'rgba(255, 255, 255, 0.6)',
  143. padding: Math.round(4 * scale)
  144. } */
  145. }
  146. },
  147. grid: {
  148. left: 0,
  149. right: 0,
  150. bottom: Math.round(60 * scale),
  151. top: Math.round(40 * scale),
  152. containLabel: true
  153. },
  154. legend: {
  155. show: false,
  156. },
  157. xAxis: {
  158. type: 'category',
  159. data: xAxis,
  160. axisLabel: {
  161. color: '#FFF',
  162. fontSize: Math.round(22 * scale)
  163. },
  164. axisTick: {
  165. alignWithLabel: true
  166. },
  167. axisLine: {
  168. show: false
  169. },
  170. axisTick: {
  171. show: false
  172. }
  173. },
  174. yAxis: {
  175. type: 'value',
  176. axisLabel: {
  177. color: '#FFF',
  178. fontSize: Math.round(22 * scale)
  179. },
  180. axisLine: {
  181. show: false
  182. },
  183. axisTick: {
  184. show: false
  185. },
  186. splitLine: {
  187. lineStyle: {
  188. type: 'dashed',
  189. color: 'rgba(255,255,255,0.6)',
  190. width: 0.5
  191. }
  192. }
  193. },
  194. series: [{
  195. name: legend[0],
  196. type: 'line',
  197. smooth: true,
  198. data: series[0],
  199. showSymbol: false,
  200. areaStyle: {
  201. normal: {
  202. color: new echarts.graphic.LinearGradient(
  203. 0, 0, 0, 1, [{
  204. offset: 0,
  205. color: 'rgba(255,255,255,0.15)'
  206. },
  207. {
  208. offset: 0.5,
  209. color: 'rgba(213,246,253,0.2)'
  210. },
  211. {
  212. offset: 1,
  213. color: 'rgba(108,160,255,1)'
  214. }
  215. ]
  216. )
  217. }
  218. },
  219. lineStyle: {
  220. color: '#fff',
  221. width: Math.round(2 * scale)
  222. }
  223. }, legend.length > 1 && {
  224. name: legend[1],
  225. type: 'line',
  226. smooth: true,
  227. data: series[1],
  228. symbol: 'none',
  229. areaStyle: {
  230. normal: {
  231. color: new echarts.graphic.LinearGradient(
  232. 0, 0, 0, 1, [{
  233. offset: 0,
  234. color: colors[1]
  235. },
  236. {
  237. offset: 1,
  238. color: '#fff'
  239. }
  240. ]
  241. )
  242. }
  243. },
  244. }]
  245. })