indicatorChart.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div class="card-chart" ref="chartRef"></div>
  3. </template>
  4. <script setup>
  5. import { onMounted, ref } from "vue";
  6. import * as echarts from "echarts";
  7. import { galleryIndicatorLine } from "./chartSeting";
  8. import { deepClone } from "@/common/commonFun";
  9. const props = defineProps({
  10. indexName: {
  11. type: String,
  12. default: "",
  13. },
  14. type: {
  15. type: String,
  16. default: "",
  17. },
  18. });
  19. let myChart = null;
  20. const chartRef = ref();
  21. let chartDataArr = ref([
  22. { date: "9/1", value: 40 },
  23. { date: "9/7", value: 60 },
  24. { date: "9/13", value: 63 },
  25. { date: "9/19", value: 68 },
  26. { date: "9/25", value: 80, feature: true },
  27. { date: "10/1", value: 85, feature: true },
  28. { date: "10/7", value: 88, feature: true },
  29. ]);
  30. onMounted(() => {
  31. myChart = echarts.init(chartRef.value);
  32. const options = deepClone(galleryIndicatorLine);
  33. myChart.setOption(options);
  34. });
  35. const processData = () => {
  36. const today = new Date();
  37. const todayString = today.toISOString().split("T")[0]; // 获取今天的日期,格式为YYYY-MM-DD
  38. const datePattern = /(\d+)\/(\d+)/; // 日期格式匹配,假设为MM/DD
  39. props.chartData.forEach((item) => {
  40. const match = item.date.match(datePattern);
  41. if (match) {
  42. const month = parseInt(match[1], 10);
  43. const day = parseInt(match[2], 10);
  44. const itemDate = new Date(today.getFullYear(), month - 1, day); // 月份从0开始,所以需要减1
  45. if (itemDate > today) {
  46. item.feature = true;
  47. }
  48. }
  49. });
  50. };
  51. </script>
  52. <style lang="scss" scoped>
  53. .card-chart {
  54. padding: 8px 4px 0 4px;
  55. width: 100%;
  56. height: 170px;
  57. box-sizing: border-box;
  58. }
  59. </style>