mirror of
https://github.com/dataease/dataease.git
synced 2025-02-23 19:12:55 +08:00
fix(图表): 修复仪表盘、水波图遇空数据指标时显示错误的问题。
Some checks are pending
Typos Check / Spell Check with Typos (push) Waiting to run
Some checks are pending
Typos Check / Spell Check with Typos (push) Waiting to run
This commit is contained in:
parent
aeda933d5c
commit
4db73f194e
@ -72,6 +72,12 @@ export class Liquid extends G2PlotChartView<LiquidOptions, G2Liquid> {
|
||||
}
|
||||
})
|
||||
})
|
||||
// 处理空数据, 只要有一个指标是空数据,就不显示图表
|
||||
const hasNoneData = chart.data?.series.some(s => !s.data?.[0])
|
||||
this.configEmptyDataStyle(newChart, hasNoneData ? [] : [1], container)
|
||||
if (hasNoneData) {
|
||||
return
|
||||
}
|
||||
return newChart
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,11 @@ export class Gauge extends G2PlotChartView<GaugeOptions, G2Gauge> {
|
||||
}
|
||||
})
|
||||
})
|
||||
const hasNoneData = chart.data?.series.some(s => !s.data?.[0])
|
||||
this.configEmptyDataStyle(newChart, hasNoneData ? [] : [1], container)
|
||||
if (hasNoneData) {
|
||||
return
|
||||
}
|
||||
return newChart
|
||||
}
|
||||
|
||||
|
@ -1922,3 +1922,37 @@ export const getTooltipItemConditionColor = item => {
|
||||
}
|
||||
return color
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置空数据样式
|
||||
* @param newChart
|
||||
* @param newData
|
||||
* @param container
|
||||
*/
|
||||
export const configEmptyDataStyle = (newChart, newData, container) => {
|
||||
/**
|
||||
* 辅助函数:移除空数据dom
|
||||
*/
|
||||
const removeEmptyDom = () => {
|
||||
const emptyElement = document.getElementById(container + '_empty')
|
||||
if (emptyElement) {
|
||||
emptyElement.parentElement.removeChild(emptyElement)
|
||||
}
|
||||
}
|
||||
removeEmptyDom()
|
||||
if (newData.length > 0) return
|
||||
if (!newData.length) {
|
||||
const emptyDom = document.createElement('div')
|
||||
emptyDom.id = container + '_empty'
|
||||
emptyDom.textContent = tI18n('data_set.no_data')
|
||||
emptyDom.setAttribute(
|
||||
'style',
|
||||
`position: absolute;
|
||||
left: 45%;
|
||||
top: 50%;`
|
||||
)
|
||||
const parent = document.getElementById(container)
|
||||
parent.insertBefore(emptyDom, parent.firstChild)
|
||||
newChart.destroy()
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ import {
|
||||
getYAxis,
|
||||
getConditions,
|
||||
handleConditionsStyle,
|
||||
addConditionsStyleColorToData
|
||||
addConditionsStyleColorToData,
|
||||
configEmptyDataStyle
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import {
|
||||
AntVAbstractChartView,
|
||||
@ -190,6 +191,10 @@ export abstract class G2PlotChartView<
|
||||
return addConditionsStyleColorToData(chart, data)
|
||||
}
|
||||
|
||||
protected configEmptyDataStyle(newChart, newData: any[], container: string) {
|
||||
configEmptyDataStyle(newChart, newData, container)
|
||||
}
|
||||
|
||||
/**
|
||||
* 流式配置公共参数,处理常用的配置,后续如果有其他通用配置也可以放进来,需要单独配置的属性在各个图表自行实现。
|
||||
* @param chart 数据库图表对象。
|
||||
|
Loading…
Reference in New Issue
Block a user