businessEnergyDistributeChart.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div style="width: 100%" :style="{height: height+'px'}" ref="myChart"></div>
  3. </template>
  4. <script>
  5. import apiOperationAnalysis from "@/api/operation/apiOperationAnalysis";
  6. export default {
  7. data() {
  8. return {
  9. option: {
  10. legend: {
  11. top: "10",
  12. icon: 'circle',
  13. textStyle: { fontSize: 14, color: "#000000" },
  14. itemGap: 20,
  15. itemWidth: 20,
  16. data: ["年度环比节能(元)"],
  17. },
  18. radar: {
  19. name: {
  20. textStyle: {
  21. color: '#333333',
  22. fontSize: 14,
  23. },
  24. },
  25. indicator: [],
  26. center: ["50%", "50%"],
  27. radius: "60%",
  28. },
  29. tooltip: {
  30. show: true,
  31. trigger: 'item',
  32. },
  33. series: [
  34. {
  35. name: "年度环比节能(元)",
  36. type: "radar",
  37. color: "#3AA7E6",
  38. label: {
  39. show: true,
  40. },
  41. areaStyle: {
  42. color: "rgba(170, 217, 255, 0.35)",
  43. },
  44. data: [
  45. {
  46. value: [],
  47. },
  48. ],
  49. },
  50. ],
  51. },
  52. }
  53. },
  54. props: {
  55. height: Number,
  56. queryData: Object
  57. },
  58. mounted() {
  59. this.$nextTick(()=>{
  60. this.init()
  61. })
  62. },
  63. methods: {
  64. init() {
  65. let chart = this.$echarts.init(this.$refs.myChart);
  66. this.chart = chart;
  67. this.getData()
  68. },
  69. getData() {
  70. return apiOperationAnalysis.getEnergyAnalysisTotal(this.queryData).then(res=>{
  71. let values = []
  72. let indicatorList = [];
  73. let max = 0;
  74. if (res) {
  75. res.forEach((item, index) => {
  76. values.push(item.value)
  77. max = Math.max(max, item.value);
  78. indicatorList.push({
  79. name: item.name,
  80. value: item.value,
  81. });
  82. });
  83. }
  84. max = Math.max(max*2, 200);
  85. console.log(max)
  86. indicatorList.forEach(item => {
  87. item.max = max;
  88. });
  89. this.option.radar.indicator = indicatorList;
  90. this.option.series[0].data[0].value = values;
  91. this.chart.setOption(this.option);
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="less" scoped>
  98. </style>