device-chart.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. (function() {
  2. Vue.component('device-chart', {
  3. template: '<div style="position:relative;height:100%;">\
  4. <div class="sk-spinner sk-spinner-chasing-dots" v-show="!isRequestEnd" style="top: 50%;left:50%;margin-left:-0.1rem;margin-top: -0.1rem;position:absolute;">\
  5. <div class="sk-dot1"></div>\
  6. <div class="sk-dot2"></div>\
  7. </div>\
  8. <div id="chart-main" v-show="isRequestEnd"></div>\
  9. </div>',
  10. props: [],
  11. data: function() {
  12. return {
  13. isRequestEnd: false
  14. }
  15. },
  16. mounted: function() {
  17. var vm = this;
  18. getRequestData(vm);
  19. }
  20. })
  21. function getRequestData(vm) {
  22. //设备发放情况
  23. intelligentAPI.equipmentDistribution({}).then(function(res) {
  24. if(res.status == 200) {
  25. var equipmentArr = res.data;
  26. equipmentArr = equipmentArr.reverse();//因为柱状图降序排列
  27. var nameArr = _.map(equipmentArr, function(equipmentData) {
  28. return equipmentData.name;
  29. })
  30. var dataArr = _.map(equipmentArr, function(equipmentData) {
  31. return equipmentData.num;
  32. })
  33. chartGenerate(nameArr, dataArr);
  34. vm.isRequestEnd = true;
  35. } else {
  36. toastr.error(res.msg)
  37. }
  38. })
  39. }
  40. function chartGenerate(nameArr, dataArr) {
  41. //【设备发放情况】柱状图
  42. var myChart = echarts.init(document.getElementById("chart-main"));
  43. var option = {
  44. calculable: false,
  45. grid: {
  46. borderWidth: 0,
  47. containLabel:true
  48. },
  49. yAxis: [{
  50. type: 'category',
  51. axisLabel: {
  52. margin: 15,
  53. textStyle: {
  54. color: "#B5E1FC",
  55. fontSize: 14
  56. }
  57. },
  58. axisLine: {
  59. lineStyle: {
  60. type: 'solid',
  61. color: '#B5E1FC', //左边线的颜色
  62. width: '1' //坐标线的宽度
  63. }
  64. },
  65. axisTick: {
  66. show: false
  67. },
  68. splitArea: {
  69. show: false
  70. },
  71. splitLine: {
  72. show: false
  73. },
  74. data: nameArr
  75. }],
  76. xAxis: [{
  77. type: 'value',
  78. axisTick: {
  79. show: false
  80. },
  81. splitArea: {
  82. show: false
  83. },
  84. splitLine: {
  85. show: false
  86. },
  87. axisLine: {
  88. lineStyle: {
  89. type: 'solid',
  90. color: '#B5E1FC', //左边线的颜色
  91. width: '1' //坐标线的宽度
  92. }
  93. },
  94. axisLabel: {
  95. margin: 15,
  96. textStyle: {
  97. color: "#B5E1FC",
  98. fontSize: 14
  99. }
  100. }
  101. }],
  102. series: [{
  103. name: '设备发放情况',
  104. type: 'bar',
  105. itemStyle: {
  106. normal: {
  107. barBorderRadius: [0, 50, 50, 0],
  108. color: '#009DFE',
  109. label: {
  110. show: true,
  111. position: 'right',
  112. textStyle: {
  113. color: "#B5E1FC",
  114. fontSize: 14
  115. }
  116. }
  117. }
  118. },
  119. barWidth: 16, //柱图宽度
  120. data: dataArr,
  121. }]
  122. };
  123. myChart.setOption(option);
  124. }
  125. })()