insectStatistics_echarts.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //判断用户是否购买app设备
  2. if (sessionStorage.getItem('purchase') == 'yes' || sessionStorage.getItem('purchase') == 'admin') {
  3. //图标的数据
  4. var staff = new Array() //测报员
  5. var insectA = new Array() //虫害
  6. var plantA = new Array() //病害
  7. function a() {
  8. $.ajax({
  9. url: 'line_chart',
  10. type: 'get',
  11. data: {
  12. ret: '2'
  13. },
  14. dataType: 'json',
  15. success: function (data) {
  16. staff.push('product')
  17. insectA.push('虫害')
  18. plantA.push('病害')
  19. for (var i = 0; i < data.length; i++) {
  20. var name = data[i].name
  21. var plant = data[i].cby_plant
  22. var insect = data[i].cby_insect
  23. staff.push(name)
  24. plantA.push(plant)
  25. insectA.push(insect)
  26. }
  27. show(staff, insectA, plantA)
  28. },
  29. error: function (error) {
  30. console.log(error)
  31. }
  32. })
  33. }
  34. a()
  35. function show (s, i, p) {
  36. var dom = document.getElementById("main");
  37. var myChart = echarts.init(dom);
  38. var app = {};
  39. option = null;
  40. option = {
  41. legend: {},
  42. tooltip: {
  43. trigger: 'axis',
  44. showContent: true,
  45. },
  46. dataset: {
  47. source: [
  48. s, i, p
  49. ]
  50. },
  51. xAxis: {
  52. type: 'category'
  53. },
  54. yAxis: {
  55. gridIndex: 0
  56. },
  57. grid: {
  58. top: '20%',
  59. right: "36%",
  60. },
  61. series: [{
  62. type: 'bar',
  63. stack: '总量',
  64. smooth: true,
  65. seriesLayoutBy: 'row'
  66. },
  67. {
  68. type: 'bar',
  69. smooth: true,
  70. stack: '总量',
  71. seriesLayoutBy: 'row'
  72. },
  73. {
  74. type: 'pie',
  75. id: 'pie',
  76. radius: '40%',
  77. center: ['86%', '50%'],
  78. label: {
  79. formatter: '{b}: {@2012} ({d}%)'
  80. },
  81. encode: {
  82. itemName: 'product',
  83. value: '2012',
  84. tooltip: '2012'
  85. }
  86. }
  87. ]
  88. };
  89. myChart.on('updateAxisPointer', function (event) {
  90. var xAxisInfo = event.axesInfo[0];
  91. if (xAxisInfo) {
  92. var dimension = xAxisInfo.value + 1;
  93. myChart.setOption({
  94. series: {
  95. id: 'pie',
  96. label: {
  97. formatter: '{b}: {@[' + dimension + ']} ({d}%)'
  98. },
  99. encode: {
  100. value: dimension,
  101. tooltip: dimension
  102. }
  103. }
  104. });
  105. }
  106. });
  107. myChart.setOption(option);
  108. if (option && typeof option === "object") {
  109. myChart.setOption(option, true);
  110. }
  111. // console.log(option.dataset.source)
  112. }
  113. } else if (sessionStorage.getItem('purchase') == 'no') {
  114. alert('未购买设备')
  115. }