curve.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="echarts">
  3. <ECharts :option="option" />
  4. </div>
  5. </template>
  6. <script setup lang="ts" name="cure">
  7. import { ECOption } from "@/components/ECharts/config";
  8. import ECharts from "@/components/ECharts/index.vue";
  9. const curveData = [
  10. { value: 30, spotName: "掘金" },
  11. { value: 90, spotName: "CSDN" },
  12. { value: 10, spotName: "Gitee" },
  13. { value: 70, spotName: "GitHub" },
  14. { value: 20, spotName: "知乎" },
  15. { value: 60, spotName: "MyBlog" },
  16. { value: 55, spotName: "简书" },
  17. { value: 80, spotName: "StackOverFlow" },
  18. { value: 50, spotName: "博客园" }
  19. ];
  20. const option: ECOption = {
  21. tooltip: {
  22. trigger: "axis",
  23. backgroundColor: "transparent",
  24. axisPointer: {
  25. type: "none"
  26. },
  27. padding: 0,
  28. formatter: (p: any) => {
  29. let dom = `<div style="width:100%; height: 70px !important; display:flex;flex-direction: column;justify-content: space-between;padding:10px;box-sizing: border-box;
  30. color:#fff; background: #6B9DFE;border-radius: 4px;font-size:14px; ">
  31. <div style="display: flex; align-items: center;"> <div style="width:5px;height:5px;background:#ffffff;border-radius: 50%;margin-right:5px"></div>平台 : ${p[0].name}</div>
  32. <div style="display: flex;align-items: center;"><div style="width:5px;height:5px;background:#ffffff;border-radius: 50%;margin-right:5px"></div>数据量 : ${p[0].value}</div>
  33. </div>`;
  34. return dom;
  35. }
  36. },
  37. toolbox: {
  38. show: true,
  39. orient: "horizontal"
  40. },
  41. grid: {
  42. left: "0",
  43. right: "0"
  44. },
  45. dataZoom: [
  46. {
  47. show: false,
  48. height: 10,
  49. xAxisIndex: [0],
  50. bottom: 0,
  51. startValue: 0,
  52. endValue: 9,
  53. handleStyle: {
  54. color: "#6b9dfe"
  55. },
  56. textStyle: {
  57. color: "transparent"
  58. }
  59. },
  60. {
  61. type: "inside",
  62. show: true,
  63. height: 0,
  64. zoomLock: true
  65. }
  66. ],
  67. xAxis: [
  68. {
  69. type: "category",
  70. data: curveData.map((val: any) => {
  71. return {
  72. value: val.spotName
  73. };
  74. }),
  75. axisTick: {
  76. show: false
  77. },
  78. axisLabel: {
  79. margin: 20,
  80. interval: 0,
  81. color: "#a1a1a1",
  82. fontSize: 14,
  83. formatter: function (name: string) {
  84. undefined;
  85. return name.length > 8 ? name.slice(0, 8) + "..." : name;
  86. }
  87. },
  88. axisLine: {
  89. lineStyle: {
  90. color: "#c0c0c0"
  91. }
  92. }
  93. }
  94. ],
  95. yAxis: [
  96. {
  97. min: 0,
  98. axisLine: {
  99. show: false
  100. },
  101. axisTick: {
  102. show: false
  103. },
  104. splitLine: {
  105. show: true,
  106. lineStyle: {
  107. color: "#c0c0c0"
  108. }
  109. },
  110. axisLabel: {
  111. color: "#a1a1a1",
  112. fontSize: 16,
  113. fontWeight: 400,
  114. formatter: function (value: number) {
  115. if (value === 0) {
  116. return value + "";
  117. } else if (value >= 10000) {
  118. return value / 10000 + "w";
  119. }
  120. return value + "";
  121. }
  122. }
  123. }
  124. ],
  125. series: [
  126. {
  127. name: "Direct",
  128. type: "bar",
  129. data: curveData.map((val: any) => {
  130. return {
  131. value: val.value
  132. };
  133. }),
  134. barWidth: "45px",
  135. itemStyle: {
  136. color: "#C5D8FF",
  137. borderRadius: [12, 12, 0, 0]
  138. },
  139. emphasis: {
  140. itemStyle: {
  141. color: "#6B9DFE"
  142. }
  143. }
  144. }
  145. ]
  146. };
  147. </script>
  148. <style lang="scss" scoped>
  149. .echarts {
  150. width: 100%;
  151. height: 100%;
  152. }
  153. </style>