PageView.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, onMounted, PropType, ref, Ref } from 'vue';
  6. import { useECharts } from '@/hooks/web/useECharts';
  7. export default defineComponent({
  8. props: {
  9. width: {
  10. type: String as PropType<string>,
  11. default: '100%',
  12. },
  13. height: {
  14. type: String as PropType<string>,
  15. default: '350px',
  16. },
  17. },
  18. setup() {
  19. const chartRef = ref<HTMLDivElement | null>(null);
  20. const { setOptions, echarts } = useECharts(chartRef as Ref<HTMLDivElement>);
  21. const option = {
  22. xAxis: {
  23. type: 'category',
  24. data: [
  25. '1月',
  26. '2月',
  27. '3月',
  28. '4月',
  29. '5月',
  30. '6月',
  31. '7月',
  32. '8月',
  33. '9月',
  34. '10月',
  35. '11月',
  36. '12月',
  37. ],
  38. },
  39. yAxis: {
  40. type: 'value',
  41. },
  42. tooltip: {
  43. show: true,
  44. },
  45. series: [
  46. {
  47. data: [
  48. {
  49. value: 8765,
  50. itemStyle: {
  51. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  52. { offset: 0, color: '#2378f7' },
  53. { offset: 0.7, color: '#2378f7' },
  54. { offset: 1, color: '#83bff6' },
  55. ]),
  56. },
  57. },
  58. {
  59. value: 4598,
  60. itemStyle: {
  61. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  62. { offset: 0, color: '#2378f7' },
  63. { offset: 0.7, color: '#2378f7' },
  64. { offset: 1, color: '#83bff6' },
  65. ]),
  66. },
  67. },
  68. {
  69. value: 13567,
  70. itemStyle: {
  71. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  72. { offset: 0, color: '#2378f7' },
  73. { offset: 0.7, color: '#2378f7' },
  74. { offset: 1, color: '#83bff6' },
  75. ]),
  76. },
  77. },
  78. {
  79. value: 4789,
  80. itemStyle: {
  81. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  82. { offset: 0, color: '#2378f7' },
  83. { offset: 0.7, color: '#2378f7' },
  84. { offset: 1, color: '#83bff6' },
  85. ]),
  86. },
  87. },
  88. {
  89. value: 9876,
  90. itemStyle: {
  91. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  92. { offset: 0, color: '#2378f7' },
  93. { offset: 0.7, color: '#2378f7' },
  94. { offset: 1, color: '#83bff6' },
  95. ]),
  96. },
  97. },
  98. {
  99. value: 5478,
  100. itemStyle: {
  101. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  102. { offset: 0, color: '#2378f7' },
  103. { offset: 0.7, color: '#2378f7' },
  104. { offset: 1, color: '#83bff6' },
  105. ]),
  106. },
  107. },
  108. {
  109. value: 3289,
  110. itemStyle: {
  111. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  112. { offset: 0, color: '#2378f7' },
  113. { offset: 0.7, color: '#2378f7' },
  114. { offset: 1, color: '#83bff6' },
  115. ]),
  116. },
  117. },
  118. {
  119. value: 13423,
  120. itemStyle: {
  121. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  122. { offset: 0, color: '#2378f7' },
  123. { offset: 0.7, color: '#2378f7' },
  124. { offset: 1, color: '#83bff6' },
  125. ]),
  126. },
  127. },
  128. {
  129. value: 6543,
  130. itemStyle: {
  131. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  132. { offset: 0, color: '#2378f7' },
  133. { offset: 0.7, color: '#2378f7' },
  134. { offset: 1, color: '#83bff6' },
  135. ]),
  136. },
  137. },
  138. {
  139. value: 7689,
  140. itemStyle: {
  141. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  142. { offset: 0, color: '#2378f7' },
  143. { offset: 0.7, color: '#2378f7' },
  144. { offset: 1, color: '#83bff6' },
  145. ]),
  146. },
  147. },
  148. {
  149. value: 8235,
  150. itemStyle: {
  151. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  152. { offset: 0, color: '#2378f7' },
  153. { offset: 0.7, color: '#2378f7' },
  154. { offset: 1, color: '#83bff6' },
  155. ]),
  156. },
  157. },
  158. {
  159. value: 6578,
  160. itemStyle: {
  161. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  162. { offset: 0, color: '#2378f7' },
  163. { offset: 0.7, color: '#2378f7' },
  164. { offset: 1, color: '#83bff6' },
  165. ]),
  166. },
  167. },
  168. ],
  169. type: 'bar',
  170. },
  171. ],
  172. };
  173. onMounted(() => {
  174. setOptions(option as any);
  175. });
  176. return { chartRef };
  177. },
  178. });
  179. </script>