waterDistributionChart.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. title: {
  16. text: "用水分布",
  17. top: "7%",
  18. left: "5%",
  19. },
  20. series: [
  21. {
  22. name: "用水量",
  23. type: "pie",
  24. radius: ["30%", "50%"],
  25. label: {
  26. show: true,
  27. formatter: "", //模板变量有 {a}、{b}、{c}、{d},分别表示系列名,数据名,数据值,百分比。{d}数据会根据value值计算百分比
  28. },
  29. data: [],
  30. emphasis: {
  31. itemStyle: {
  32. shadowBlur: 10,
  33. shadowOffsetX: 0,
  34. shadowColor: "rgba(0, 0, 0, 0.5)",
  35. },
  36. },
  37. labelLine: {
  38. show: true,
  39. length: 20,
  40. length2: 60,
  41. },
  42. },
  43. ],
  44. },
  45. };
  46. },
  47. props: {
  48. height: Number,
  49. queryData: Object,
  50. },
  51. mounted() {
  52. this.$nextTick(() => {
  53. this.initChart();
  54. });
  55. },
  56. methods: {
  57. initChart() {
  58. let chart = this.$echarts.init(this.$refs.myChart);
  59. this.chart = chart;
  60. this.$util.chartsResize(this.chart);
  61. this.option = this.$util.dataUtil.circleChartConfig(this.option)
  62. chart.setOption(this.option);
  63. this.getData();
  64. },
  65. getData() {
  66. this.loading = true;
  67. return apiDashboard.getWaterCircleInfoList(this.queryData).then((res) => {
  68. this.option.series[0].data = res;
  69. this.option = this.$util.dataUtil.circleChartConfig(this.option)
  70. this.chart.setOption(this.option);
  71. this.loading = false;
  72. }).catch(err=>{
  73. this.loading = false;
  74. });
  75. },
  76. },
  77. };
  78. </script>
  79. <template>
  80. <a-spin :spinning="loading">
  81. <div style="width: 100%" :style="{ height: height + 'px' }" ref="myChart"></div>
  82. </a-spin>
  83. </template>
  84. <style lang="less" scoped></style>