indicatorChart.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. chartData: {
  19. type: Array,
  20. default: () => [],
  21. },
  22. isDark: {
  23. type: Boolean,
  24. default: false
  25. },
  26. });
  27. let myChart = null;
  28. const chartRef = ref();
  29. onMounted(() => {
  30. myChart = echarts.init(chartRef.value);
  31. const options = deepClone(galleryIndicatorLine);
  32. // options.yAxis.name = props.indexName;
  33. options.xAxis.data = props.chartData.dates
  34. options.series[0].name = props.chartData.disease_risk_name
  35. options.series[0].data = props.chartData.disease_risk
  36. options.series[1].name = props.chartData.growth_risk_name
  37. options.series[1].data = props.chartData.growth_risk
  38. options.series[2].name = props.chartData.pheno_param1_name
  39. options.series[2].data = props.chartData.pheno_param1
  40. options.series[3].name = props.chartData.pheno_param2_name
  41. options.series[3].data = props.chartData.pheno_param2
  42. options.series[4].name = props.chartData.pheno_param3_name
  43. options.series[4].data = props.chartData.pheno_param3
  44. myChart.setOption(options);
  45. });
  46. const processData = () => {
  47. const today = new Date();
  48. const todayString = today.toISOString().split("T")[0]; // 获取今天的日期,格式为YYYY-MM-DD
  49. const datePattern = /(\d+)\/(\d+)/; // 日期格式匹配,假设为MM/DD
  50. props.chartData.forEach((item) => {
  51. const match = item.date.match(datePattern);
  52. if (match) {
  53. const month = parseInt(match[1], 10);
  54. const day = parseInt(match[2], 10);
  55. const itemDate = new Date(today.getFullYear(), month - 1, day); // 月份从0开始,所以需要减1
  56. if (itemDate > today) {
  57. item.feature = true;
  58. }
  59. }
  60. });
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. .card-chart {
  65. padding: 8px 4px 0 4px;
  66. width: 100%;
  67. height: 160px;
  68. box-sizing: border-box;
  69. }
  70. </style>