chart.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="content">
  3. <l-echart ref="domMyChart" class="echarts"></l-echart>
  4. <!-- <view
  5. @click="initEcharts"
  6. :prop="option"
  7. ref="domMyChart"
  8. id="linEcharts"
  9. class="echarts"
  10. >
  11. </view> -->
  12. </view>
  13. </template>
  14. <script setup>
  15. import * as echarts from "echarts";
  16. import { onLoad, onShow, onHide, onLaunch, onResize } from "@dcloudio/uni-app";
  17. import { defineComponent, ref, onMounted, nextTick } from "vue";
  18. const props = defineProps({
  19. currentDateList: {
  20. type: Object,
  21. default: null,
  22. },
  23. });
  24. let myChart;
  25. const domMyChart = ref(null);
  26. var datas = [
  27. {
  28. name: "漏检任务",
  29. value: 0,
  30. },
  31. {
  32. name: "已巡检任务",
  33. value: 0,
  34. },
  35. ];
  36. datas[0].value = props.currentDateList[0].undetectedCount;
  37. datas[1].value = props.currentDateList[0].patrolledCount;
  38. let option = {
  39. color: ["#F07D28", "#00CDAC"],
  40. title: [
  41. {
  42. text: "今日巡检情况",
  43. left: "center",
  44. top: 15,
  45. textStyle: {
  46. color: "black",
  47. fontWeight: "normal",
  48. fontSize: 14,
  49. },
  50. },
  51. {
  52. text: [
  53. `{value|${props.currentDateList[0].planSonCount}}`,
  54. "{name|巡检总数}",
  55. ].join("\n "),
  56. top: "40%",
  57. left: "center",
  58. textStyle: {
  59. color: "black",
  60. fontWeight: "normal",
  61. fontSize: 14,
  62. lineHeight: 22,
  63. rich: {
  64. name: {
  65. fontFamily: "PingFangSC-Regular",
  66. fontSize: 13,
  67. color: "rgba(0,0,0,0.45)",
  68. lineHeight: 22,
  69. marginBottom: "5px",
  70. },
  71. value: {
  72. fontFamily: "HelveticaNeue",
  73. fontSize: 24,
  74. color: "rgba(0,0,0,0.85)",
  75. lineHeight: 30,
  76. },
  77. },
  78. },
  79. },
  80. ],
  81. series: {
  82. type: "pie",
  83. radius: [40, 80],
  84. height: "100%",
  85. left: "center",
  86. width: "100%",
  87. itemStyle: {
  88. borderColor: "#fff",
  89. borderWidth: 1,
  90. },
  91. label: {
  92. alignTo: "edge",
  93. formatter: function (el) {
  94. return `${el.name}\n${el.value}`;
  95. },
  96. minMargin: 5,
  97. edgeDistance: 10,
  98. lineHeight: 20,
  99. rich: {
  100. time: {
  101. fontSize: 10,
  102. color: "#999",
  103. },
  104. },
  105. },
  106. labelLine: {
  107. length: 25,
  108. length2: 0,
  109. maxSurfaceAngle: 80,
  110. },
  111. labelLayout: function (params) {
  112. // var isLeft = params.labelRect.x < myChart.getWidth() / 2;
  113. var isLeft = params.labelRect.x < myChart.nodeWidth / 2;
  114. var points = params.labelLinePoints;
  115. points[2][0] = isLeft
  116. ? params.labelRect.x
  117. : params.labelRect.x + params.labelRect.width;
  118. return {
  119. labelLinePoints: points,
  120. };
  121. },
  122. data: datas,
  123. },
  124. };
  125. function initEcharts() {
  126. // let dom = uni.createSelectorQuery().select("#linEcharts");
  127. // myChart = echarts.init(document.getElementById("linEcharts"));
  128. // 观测更新的数据在 view 层可以直接访问到
  129. // myChart.setOption(option);
  130. myChart = domMyChart.value;
  131. myChart.init(echarts, (myChart) => {
  132. myChart.setOption(option);
  133. });
  134. }
  135. onLoad(() => {
  136. nextTick(() => {
  137. initEcharts();
  138. });
  139. });
  140. onResize(() => {
  141. myChart.resize();
  142. });
  143. </script>
  144. <style>
  145. .content {
  146. display: flex;
  147. flex-direction: column;
  148. align-items: center;
  149. justify-content: center;
  150. }
  151. .echarts {
  152. width: 100%;
  153. height: 600rpx;
  154. /* margin-top: 70rpx; */
  155. /* background:pink */
  156. }
  157. </style>