InterfaceMonth.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="spatial-analysis-statistic">
  3. <div class="title">{{ title }}</div>
  4. <div class="echart-container" id="defect-column" ref="domRef"></div>
  5. </div>
  6. </template>
  7. <script>
  8. import {
  9. defineComponent,
  10. reactive,
  11. toRefs,
  12. onMounted,
  13. ref,
  14. watch,
  15. getCurrentInstance,
  16. shallowRef,
  17. onUnmounted,
  18. } from 'vue';
  19. import moment from 'moment';
  20. import { queryApiUseCountMouths } from '/@/api/interface/interface';
  21. const props = {
  22. type: {
  23. type: Object,
  24. },
  25. };
  26. export default defineComponent({
  27. name: 'InterfaceMonth',
  28. components: {},
  29. props,
  30. setup(props) {
  31. const data = reactive({
  32. title: '月度接口访问次数',
  33. interval: null,
  34. });
  35. const domRef = ref(null);
  36. const { proxy } = getCurrentInstance();
  37. const echarts = proxy.$echarts;
  38. const mychart = shallowRef(null);
  39. /**
  40. * 查询统计数据
  41. */
  42. const queryData = async () => {
  43. const res = await queryApiUseCountMouths();
  44. let xAxisData = [],
  45. seriesData = [];
  46. if (res) {
  47. res.mouths.map((item) => {
  48. xAxisData.push(item);
  49. });
  50. res.nums.map((item) => {
  51. seriesData.push(parseInt(item));
  52. });
  53. }
  54. if (seriesData.length < 1 || xAxisData.length < 1) return;
  55. const option = getOption(seriesData, xAxisData);
  56. setEcharts(option);
  57. };
  58. const setEcharts = (option) => {
  59. if (mychart.value) mychart.value.clear();
  60. mychart.value = echarts.init(domRef.value);
  61. //const option = getOption();
  62. mychart.value.setOption(option,true);
  63. window.onresize = () => {
  64. mychart.value.resize();
  65. };
  66. };
  67. const getOption = (seriesData, xAxisData) => {
  68. //const seriesData = [123, 60, 25, 28, 42, 39, 20, 40, 123, 60, 25, 28];
  69. const maxValue = Math.max.apply(null, seriesData);
  70. //const xAxisData = ['01月','02月','03月','04月','05月','06月','07月','08月','09月','10月','11月','12月',];
  71. const colorList = [
  72. {
  73. type: 'linear',
  74. x: 0,
  75. y: 0,
  76. x2: 0,
  77. y2: 1,
  78. colorStops: [
  79. {
  80. offset: 0,
  81. color: 'rgba(6,113,221,1)', // 0% 处的颜色
  82. },
  83. {
  84. offset: 0.5,
  85. color: 'rgba(6,113,221,0.9)', // 0% 处的颜色
  86. },
  87. {
  88. offset: 1,
  89. color: 'rgba(6,113,221,0)', // 100% 处的颜色
  90. },
  91. ],
  92. global: false, // 缺省为 false
  93. },
  94. {
  95. type: 'linear',
  96. x: 0,
  97. y: 0,
  98. x2: 0,
  99. y2: 1,
  100. colorStops: [
  101. {
  102. offset: 0,
  103. color: 'rgba(237,172,75,1)', // 0% 处的颜色
  104. },
  105. {
  106. offset: 0.5,
  107. color: 'rgba(237,172,75,0.9)', // 0% 处的颜色
  108. },
  109. {
  110. offset: 1,
  111. color: 'rgba(237,172,75,0.2)', // 100% 处的颜色 'rgba(6,113,221,0.2)'
  112. },
  113. ],
  114. global: false, // 缺省为 false
  115. },
  116. ];
  117. let seriesSymboleData = [];
  118. seriesData.map((item) => {
  119. seriesSymboleData.push({
  120. value: item,
  121. symbol: 'rect',
  122. symbolSize: ['100%', 4],
  123. itemStyle: {
  124. color: item < maxValue ? 'rgba(6,113,221,1)' : 'rgba(237,172,75,1)',
  125. },
  126. });
  127. });
  128. return {
  129. tooltip: {
  130. trigger: 'axis',
  131. axisPointer: {
  132. type: 'none',
  133. },
  134. formatter: function (params) {
  135. return params[0].name + ': ' + params[0].value;
  136. },
  137. },
  138. xAxis: {
  139. data: xAxisData,
  140. axisTick: { show: false },
  141. axisLine: { show: false },
  142. axisLabel: {
  143. color: '#000',
  144. },
  145. axisLine: {
  146. show: true,
  147. lineStyle: {
  148. color: 'rgba(222, 222, 222, 1)',
  149. },
  150. },
  151. },
  152. yAxis: {
  153. splitLine: { show: false },
  154. axisTick: { show: false },
  155. axisLine: { show: false },
  156. axisLabel: { show: true },
  157. },
  158. grid: {
  159. //极坐标
  160. top: '10%',
  161. left: '1%',
  162. right: '1%',
  163. bottom: '1%',
  164. containLabel: true,
  165. },
  166. series: [
  167. {
  168. name: 'hill',
  169. type: 'pictorialBar',
  170. barCategoryGap: '80%',
  171. // symbol: 'path://M0,10 L10,10 L5,0 L0,10 z',
  172. symbol: 'rect',
  173. itemStyle: {
  174. opacity: 1,
  175. color: (params) => {
  176. let color = colorList[0];
  177. if (params.data === maxValue) color = colorList[1];
  178. return color;
  179. },
  180. },
  181. emphasis: {
  182. itemStyle: {
  183. opacity: 1,
  184. },
  185. },
  186. data: seriesData,
  187. z: 10,
  188. },
  189. {
  190. name: 'glyph',
  191. type: 'pictorialBar',
  192. barGap: '-100%',
  193. symbolPosition: 'end',
  194. //symbolSize: 50,
  195. symbolOffset: [0, '-160%'],
  196. data: seriesSymboleData,
  197. },
  198. ],
  199. animationDuration: 0,//这里两个动画设置可以让图表更顺滑
  200. animationEasing: 'cubicInOut'//这里两个动画设置可以让图表更顺滑
  201. };
  202. };
  203. onMounted(() => {
  204. if (data.interval) return;
  205. data.interval = setInterval(() => {
  206. queryData();
  207. }, 3000);
  208. });
  209. onUnmounted(() => {
  210. if (data.interval) clearInterval(data.interval);
  211. });
  212. return {
  213. domRef,
  214. mychart,
  215. ...toRefs(data),
  216. queryData,
  217. setEcharts,
  218. getOption,
  219. };
  220. },
  221. });
  222. </script>
  223. <style lang="less" scoped>
  224. .spatial-analysis-statistic {
  225. height: 100%;
  226. width: 100%;
  227. padding: 1rem;
  228. .title {
  229. height: 1.2rem;
  230. font-family: Source Han Sans CN;
  231. font-size: 1.012rem;
  232. font-weight: bold;
  233. line-height: normal;
  234. letter-spacing: 0em;
  235. color: #3d3d3d;
  236. margin-bottom: 1.2rem;
  237. }
  238. .echart-container {
  239. height: calc(100% - 2.4rem);
  240. width: 100%;
  241. }
  242. }
  243. </style>