index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. const app = getApp();
  2. import * as echarts from '../../../../ec-canvas/echarts' // 这个是自己实际的目录
  3. Component({
  4. data:{
  5. Ec: { lazyLoad: true, },
  6. },
  7. lifetimes: {
  8. attached: function () {
  9. this.init()
  10. },
  11. moved: function () { },
  12. detached: function () { },
  13. },
  14. methods:{
  15. init(){
  16. var that = this;
  17. that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => {
  18. const chart = echarts.init(canvas, null, {
  19. width: width,
  20. height: height,
  21. devicePixelRatio: dpr
  22. });
  23. var option = that.getOrderWarnOption();
  24. chart.setOption(option);
  25. return chart;
  26. });
  27. },
  28. getOrderWarnOption(){
  29. var list = [
  30. {name:"已使用",data:[{name:"2022",value:35,},{name:"2021",value:30,},{name:"2020",value:20,},{name:"2019",value:30,}]},
  31. {name:"未使用",data:[{name:"2022",value:50,},{name:"2021",value:30,},{name:"2020",value:30,},{name:"2019",value:30,}]},
  32. {name:"不良率",data:[{name:"2022",value:10,},{name:"2021",value:5,},{name:"2020",value:10,},{name:"2019",value:10,}]},
  33. ]
  34. var fontSize = 10
  35. var fontColor = "#999999"
  36. return {
  37. color:["#2D59E6","#7FD1FF","#E1291C","#2D59E6"],
  38. title:{
  39. text:"历年所有试剂的数据",
  40. show:0,
  41. textStyle:{
  42. color:fontColor,
  43. fontSize:fontSize,
  44. },
  45. left:'15%',
  46. top:0,
  47. },
  48. grid: {
  49. top: '20%',
  50. left: '6%',
  51. right: '4%',
  52. bottom: '3%',
  53. containLabel: true
  54. },
  55. tooltip: {
  56. trigger: 'axis',
  57. axisPointer: {
  58. type: 'cross',
  59. }
  60. },
  61. legend:{
  62. icon:"circle",
  63. right:'auto',
  64. top:0,
  65. itemWidth:fontSize*0.8,
  66. itemHeight:fontSize,
  67. textStyle:{
  68. fontSize:fontSize,
  69. color:fontColor,
  70. },
  71. data:list.map(item=>item.name)
  72. },
  73. yAxis: [
  74. {
  75. type: 'value',
  76. name:"",
  77. splitNumber:5,
  78. axisTick:{show:false,},
  79. axisLabel:{
  80. fontSize:fontSize,
  81. color:fontColor,
  82. },
  83. nameTextStyle:{
  84. fontSize:fontSize,
  85. color:fontColor,
  86. },
  87. nameGap:5,
  88. },
  89. {
  90. type: 'value',
  91. position: 'right',
  92. splitNumber:5,
  93. boundaryGap:[0,1],
  94. name:"%",
  95. axisTick:{show:false,},
  96. splitLine:{show:false,},
  97. axisLabel:{
  98. fontSize:fontSize,
  99. color:fontColor,
  100. },
  101. nameTextStyle:{
  102. fontSize:fontSize,
  103. color:fontColor,
  104. },
  105. nameGap:5,
  106. },
  107. ],
  108. xAxis: {
  109. type: 'category',
  110. // boundaryGap: false,
  111. axisTick:{show:false,},
  112. axisLabel:{
  113. fontSize:fontSize,
  114. color:fontColor,
  115. },
  116. data: list[0].data.map(item=>item.name)
  117. },
  118. series:this.setOptItem(list),
  119. }
  120. },
  121. setOptItem(list){
  122. var data = []
  123. var fontSize = 10
  124. for(var i in list){
  125. if(i==2){
  126. data.push({
  127. type: 'line',
  128. name:"%",
  129. silent:1,
  130. yAxisIndex: 1,
  131. barMaxWidth:fontSize*1.5,
  132. name:list[i].name,
  133. data:list[i].data
  134. })
  135. }else{
  136. data.push({
  137. type: 'bar',
  138. stack: 'Total',
  139. name:"千万",
  140. silent:1,
  141. barMaxWidth:fontSize*1.5,
  142. name:list[i].name,
  143. data:list[i].data
  144. })
  145. }
  146. }
  147. return data
  148. },
  149. },
  150. })