Commit fdd6f2c25b4d3a0b5aa51d3e0bd40a3a88ae1e54

Authored by xp.Huang
2 parents 3fd1f6ee e5b811c3

Merge branch 'local_dev_latest' into 'main_dev'

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

See merge request yunteng/thingskit-view!222
... ... @@ -45,11 +45,12 @@ export const lineSeriesItem = {
45 45
46 46 export const option = {
47 47 tooltip: {
48   - show: true,
49 48 trigger: 'axis',
50 49 axisPointer: {
51   - show: true,
52   - type: 'shadow'
  50 + type: 'cross',
  51 + crossStyle: {
  52 + color: '#999'
  53 + }
53 54 }
54 55 },
55 56 legend: {
... ...
... ... @@ -62,17 +62,30 @@ const option = computed(() => {
62 62 // dataset 无法变更条数的补丁
63 63 watch(
64 64 () => props.chartConfig.option.dataset,
65   - (newData: { dimensions: any }, oldData) => {
  65 + (newData: any, oldData) => {
66 66 try {
67 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 88 replaceMergeArr.value = ['series']
75   - props.chartConfig.option.series = seriesArr
76 89 nextTick(() => {
77 90 replaceMergeArr.value = []
78 91 })
... ...
1 1 <template>
2   - <collapse-item name="数据源(option配置里的内容)" :expanded="true">
  2 + <collapse-item name="数据源(option配置里的内容,注意去除末尾分号)" :expanded="true">
3 3 <monaco-editor v-model:modelValue="optionData.dataset" width="400px" height="480px" language="json" />
4 4 </collapse-item>
5 5 </template>
... ...