indicatorChart.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. import eventBus from "@/api/eventBus";
  10. const props = defineProps({
  11. indexName: {
  12. type: String,
  13. default: "",
  14. },
  15. type: {
  16. type: String,
  17. default: "",
  18. },
  19. chartData: {
  20. type: Object,
  21. default: () => {},
  22. },
  23. isDark: {
  24. type: Boolean,
  25. default: false
  26. },
  27. });
  28. let myChart = ref(null);
  29. const chartRef = ref();
  30. const options = ref({});
  31. onMounted(() => {
  32. myChart.value = echarts.init(chartRef.value);
  33. options.value = deepClone(galleryIndicatorLine);
  34. updateValue(false)
  35. });
  36. eventBus.on("chart:updateOption",(data)=>{
  37. updateValue(true, data)
  38. })
  39. const updateValue = (isUpdate, data) =>{
  40. let chartList = {}
  41. if (isUpdate) {
  42. // const filterData = filterDataAfterJanuary(data)
  43. chartList = data
  44. } else {
  45. chartList = props.chartData
  46. }
  47. myChart.value.clear()
  48. if(chartList.dates?.length){
  49. options.value.xAxis.data = chartList.dates.map(item => item.slice(5))
  50. options.value.series[0].name = chartList.diseaseRiskName
  51. options.value.legend.data[0] = chartList.diseaseRiskName
  52. options.value.series[0].data = chartList.diseaseRisk
  53. options.value.series[1].name = chartList.growthRiskName
  54. options.value.legend.data[1] = chartList.growthRiskName
  55. options.value.series[1].data = chartList.growthRisk
  56. options.value.series[2].name = chartList.phenoParam1Name
  57. options.value.legend.data[2] = chartList.phenoParam1Name
  58. options.value.series[2].data = chartList.phenoParam1
  59. options.value.series[3].name = chartList.phenoParam2Name
  60. options.value.legend.data[3] = chartList.phenoParam2Name
  61. options.value.series[3].data = chartList.phenoParam2
  62. options.value.series[4].name = chartList?.phenoParam3Name
  63. options.value.legend.data[4] = chartList.phenoParam3Name
  64. options.value.series[4].data = chartList?.phenoParam3
  65. if (props.isDark) {
  66. options.value.yAxis[0].splitLine.lineStyle.color = "#333333"
  67. options.value.yAxis[0].axisLabel.textStyle.color = "#999999"
  68. options.value.xAxis.axisLine.lineStyle.color = "#333333"
  69. options.value.xAxis.axisLabel.textStyle.color = "#999999"
  70. options.value.legend.textStyle.color = "#fff"
  71. }
  72. myChart.value.setOption(options.value);
  73. }
  74. }
  75. const processData = () => {
  76. const today = new Date();
  77. const todayString = today.toISOString().split("T")[0]; // 获取今天的日期,格式为YYYY-MM-DD
  78. const datePattern = /(\d+)\/(\d+)/; // 日期格式匹配,假设为MM/DD
  79. props.chartData.forEach((item) => {
  80. const match = item.date.match(datePattern);
  81. if (match) {
  82. const month = parseInt(match[1], 10);
  83. const day = parseInt(match[2], 10);
  84. const itemDate = new Date(today.getFullYear(), month - 1, day); // 月份从0开始,所以需要减1
  85. if (itemDate > today) {
  86. item.feature = true;
  87. }
  88. }
  89. });
  90. };
  91. </script>
  92. <style lang="scss" scoped>
  93. .card-chart {
  94. padding: 8px 4px 0 4px;
  95. width: 100%;
  96. height: 180px;
  97. box-sizing: border-box;
  98. }
  99. </style>