waterDistributionChart.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <script>
  2. import apiDashboard from "@/api/dashboard/apiDashboard";
  3. export default {
  4. data() {
  5. return {
  6. loading: false,
  7. option: {
  8. tooltip: {
  9. trigger: "item",
  10. },
  11. legend: {
  12. bottom: "8%",
  13. icon: "circle",
  14. },
  15. textStyle: {
  16. fontSize: "14px",
  17. fontFamily: "PingFangSC-Regular, serif",
  18. },
  19. title: [
  20. {
  21. text: "用水分布", //主标题
  22. left: "5%", //标题的位置 默认是left,其余还有center、right属性
  23. top: "7%",
  24. textStyle: {
  25. color: "#000",
  26. fontSize: 18,
  27. fontWeight: "normal",
  28. },
  29. },
  30. {
  31. subtext: "单位: m³", //主标题
  32. right: "0%", //标题的位置 默认是left,其余还有center、right属性
  33. bottom: "15%",
  34. subtextStyle: {
  35. color: "rgb(160,160,160)",
  36. fontSize: 14,
  37. fontWeight: "normal",
  38. },
  39. },
  40. ],
  41. series: [
  42. {
  43. name: "用水量",
  44. type: "pie",
  45. radius: ["30%", "50%"],
  46. label: {
  47. show: true,
  48. formatter: "", //模板变量有 {a}、{b}、{c}、{d},分别表示系列名,数据名,数据值,百分比。{d}数据会根据value值计算百分比
  49. },
  50. data: [],
  51. emphasis: {
  52. itemStyle: {
  53. shadowBlur: 10,
  54. shadowOffsetX: 0,
  55. shadowColor: "rgba(0, 0, 0, 0.5)",
  56. },
  57. },
  58. labelLine: {
  59. show: true,
  60. length: 20,
  61. length2: 60,
  62. },
  63. },
  64. ],
  65. },
  66. };
  67. },
  68. props: {
  69. height: Number,
  70. queryData: Object,
  71. },
  72. mounted() {
  73. this.$nextTick(() => {
  74. this.initChart();
  75. });
  76. },
  77. methods: {
  78. initChart() {
  79. let chart = this.$echarts.init(this.$refs.myChart);
  80. this.chart = chart;
  81. this.$util.chartsResize(this.chart);
  82. this.option = this.$util.dataUtil.circleChartConfig(this.option);
  83. chart.setOption(this.option);
  84. this.getData();
  85. },
  86. getData() {
  87. this.loading = true;
  88. return apiDashboard
  89. .getWaterCircleInfoList(this.queryData)
  90. .then((res) => {
  91. this.option.series[0].data = res;
  92. this.option = this.$util.dataUtil.circleChartConfig(this.option);
  93. this.chart.setOption(this.option);
  94. this.loading = false;
  95. })
  96. .catch((err) => {
  97. this.loading = false;
  98. });
  99. },
  100. },
  101. };
  102. </script>
  103. <template>
  104. <a-spin :spinning="loading">
  105. <div
  106. style="width: 100%"
  107. :style="{ height: height + 'px' }"
  108. ref="myChart"
  109. ></div>
  110. </a-spin>
  111. </template>
  112. <style lang="less" scoped></style>