Commit e5b811c366024a2e57f26a7ae694ebaed454979f

Authored by fengtao
Committed by xp.Huang
1 parent 3fd1f6ee

fix(src/packages/components/Charts): 修复柱状和折线图,鼠标移入提示框里数据重复显示

@@ -45,11 +45,12 @@ export const lineSeriesItem = { @@ -45,11 +45,12 @@ export const lineSeriesItem = {
45 45
46 export const option = { 46 export const option = {
47 tooltip: { 47 tooltip: {
48 - show: true,  
49 trigger: 'axis', 48 trigger: 'axis',
50 axisPointer: { 49 axisPointer: {
51 - show: true,  
52 - type: 'shadow' 50 + type: 'cross',
  51 + crossStyle: {
  52 + color: '#999'
  53 + }
53 } 54 }
54 }, 55 },
55 legend: { 56 legend: {
@@ -62,17 +62,30 @@ const option = computed(() => { @@ -62,17 +62,30 @@ const option = computed(() => {
62 // dataset 无法变更条数的补丁 62 // dataset 无法变更条数的补丁
63 watch( 63 watch(
64 () => props.chartConfig.option.dataset, 64 () => props.chartConfig.option.dataset,
65 - (newData: { dimensions: any }, oldData) => { 65 + (newData: any, oldData) => {
66 try { 66 try {
67 if (!isObject(newData) || !('dimensions' in newData)) return 67 if (!isObject(newData) || !('dimensions' in newData)) return
68 - if (Array.isArray(newData?.dimensions)) {  
69 - const seriesArr = []  
70 - for (let i = 0; i < newData.dimensions.length - 1; i++) {  
71 - seriesArr.push(cloneDeep(barSeriesItem),cloneDeep(lineSeriesItem)) 68 + if (Array.isArray((newData as any)?.dimensions)) {
  69 + const seriesArr: typeof barSeriesItem[] = []
  70 + // 对oldData进行判断,防止传入错误数据之后对旧维度判断产生干扰
  71 + // 此处计算的是dimensions的Y轴维度,若是dimensions.length为0或1,则默认为1,排除X轴维度干扰
  72 + const oldDimensions =
  73 + Array.isArray(oldData?.dimensions) && oldData.dimensions.length >= 1 ? oldData.dimensions.length : 1
  74 + const newDimensions = (newData as any).dimensions.length >= 1 ? (newData as any).dimensions.length : 1
  75 + const dimensionsGap = newDimensions - oldDimensions
  76 + if (dimensionsGap < 0) {
  77 + props.chartConfig.option.series.splice(newDimensions - 1)
  78 + } else if (dimensionsGap > 0) {
  79 + if (!oldData || !oldData?.dimensions || !Array.isArray(oldData?.dimensions) || !oldData?.dimensions.length) {
  80 + props.chartConfig.option.series = []
  81 + }
  82 + for (let i = 0; i < dimensionsGap; i++) {
  83 + seriesArr.push(cloneDeep(barSeriesItem))
  84 + }
  85 + props.chartConfig.option.series.push(...seriesArr)
72 } 86 }
73 - useEchartsMapLegend(props.chartConfig, seriesArr) 87 + useEchartsMapLegend(props.chartConfig, props.chartConfig.option.series)
74 replaceMergeArr.value = ['series'] 88 replaceMergeArr.value = ['series']
75 - props.chartConfig.option.series = seriesArr  
76 nextTick(() => { 89 nextTick(() => {
77 replaceMergeArr.value = [] 90 replaceMergeArr.value = []
78 }) 91 })
1 <template> 1 <template>
2 - <collapse-item name="数据源(option配置里的内容)" :expanded="true"> 2 + <collapse-item name="数据源(option配置里的内容,注意去除末尾分号)" :expanded="true">
3 <monaco-editor v-model:modelValue="optionData.dataset" width="400px" height="480px" language="json" /> 3 <monaco-editor v-model:modelValue="optionData.dataset" width="400px" height="480px" language="json" />
4 </collapse-item> 4 </collapse-item>
5 </template> 5 </template>