Chart.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <script lang="ts" setup>
  2. import { onMounted, ref, Ref } from 'vue';
  3. import { useECharts } from '@/hooks/web/useECharts';
  4. import { getReqChartBy30 } from '@/api/aigc/statictic';
  5. const chartRef = ref<HTMLDivElement | null>(null);
  6. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  7. onMounted(async () => {
  8. const data = await getReqChartBy30();
  9. const xData: any = [];
  10. const yData: any = [];
  11. data.forEach((i: any) => {
  12. xData.push(i.date);
  13. yData.push(i.tokens);
  14. });
  15. setOptions({
  16. tooltip: {
  17. trigger: 'axis',
  18. axisPointer: {
  19. lineStyle: {
  20. width: 1,
  21. color: '#019680',
  22. },
  23. },
  24. },
  25. xAxis: {
  26. type: 'category',
  27. boundaryGap: false,
  28. data: xData,
  29. splitLine: {
  30. show: true,
  31. lineStyle: {
  32. width: 1,
  33. type: 'solid',
  34. color: 'rgba(226,226,226,0.5)',
  35. },
  36. },
  37. axisTick: {
  38. show: false,
  39. },
  40. },
  41. yAxis: [
  42. {
  43. type: 'value',
  44. splitNumber: 4,
  45. axisTick: {
  46. show: false,
  47. },
  48. splitArea: {
  49. show: true,
  50. areaStyle: {
  51. color: ['rgba(255,255,255,0.2)', 'rgba(226,226,226,0.2)'],
  52. },
  53. },
  54. },
  55. ],
  56. grid: { left: '1%', right: '1%', top: '2 %', bottom: 0, containLabel: true },
  57. series: [
  58. {
  59. smooth: true,
  60. data: yData,
  61. type: 'line',
  62. areaStyle: {},
  63. itemStyle: {
  64. color: '#5ab1ef',
  65. },
  66. },
  67. ],
  68. });
  69. });
  70. </script>
  71. <template>
  72. <div>
  73. <h3 class="my-2 mb-6 text-lg">近30天请求汇总</h3>
  74. <div ref="chartRef" class="w-full h-60"></div>
  75. </div>
  76. </template>