mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 04:12:11 +08:00
fix(图表): 修复图表的提示配置,自定义显示指标字段时,如果指标字段是非数值类型图表报错的问题
This commit is contained in:
committed by
jianneng-fit2cloud
parent
b81b6c9fa0
commit
8e3e666b25
@@ -630,9 +630,15 @@ public class ChartDataBuild {
|
||||
DynamicValueDTO valueDTO = new DynamicValueDTO();
|
||||
ChartViewFieldDTO f = view.getExtLabel().get(ii);
|
||||
int idx = extLabelStart + ii;
|
||||
BigDecimal value = (idx < row.length && StringUtils.isNotEmpty(row[idx])) ? new BigDecimal(row[idx]) : null;
|
||||
if (idx < row.length && StringUtils.isNotEmpty(row[idx])) {
|
||||
try {
|
||||
valueDTO.setValue(new BigDecimal(row[idx]));
|
||||
} catch (NumberFormatException e) {
|
||||
// 时间等非数值类型,保留原始字符串
|
||||
valueDTO.setStringValue(row[idx]);
|
||||
}
|
||||
}
|
||||
valueDTO.setFieldId(f.getId());
|
||||
valueDTO.setValue(value);
|
||||
dynamicLabelValue.add(valueDTO);
|
||||
}
|
||||
}
|
||||
@@ -641,9 +647,15 @@ public class ChartDataBuild {
|
||||
DynamicValueDTO valueDTO = new DynamicValueDTO();
|
||||
ChartViewFieldDTO f = view.getExtTooltip().get(ii);
|
||||
int idx = extTooltipStart + ii;
|
||||
BigDecimal value = (idx < row.length && StringUtils.isNotEmpty(row[idx])) ? new BigDecimal(row[idx]) : null;
|
||||
if (idx < row.length && StringUtils.isNotEmpty(row[idx])) {
|
||||
try {
|
||||
valueDTO.setValue(new BigDecimal(row[idx]));
|
||||
} catch (NumberFormatException e) {
|
||||
// 时间等非数值类型,保留原始字符串
|
||||
valueDTO.setStringValue(row[idx]);
|
||||
}
|
||||
}
|
||||
valueDTO.setFieldId(f.getId());
|
||||
valueDTO.setValue(value);
|
||||
dynamicTooltipValue.add(valueDTO);
|
||||
}
|
||||
}
|
||||
@@ -1633,9 +1645,15 @@ public class ChartDataBuild {
|
||||
for (int ii = 0; ii < view.getExtLabel().size(); ii++) {
|
||||
DynamicValueDTO valueDTO = new DynamicValueDTO();
|
||||
ChartViewFieldDTO chartViewFieldDTO = view.getExtLabel().get(ii);
|
||||
BigDecimal value = StringUtils.isEmpty(row[ii + (size - extSize)]) ? null : new BigDecimal(row[ii + (size - extSize)]);
|
||||
String raw = row[ii + (size - extSize)];
|
||||
if (StringUtils.isNotEmpty(raw)) {
|
||||
try {
|
||||
valueDTO.setValue(new BigDecimal(raw));
|
||||
} catch (NumberFormatException e) {
|
||||
valueDTO.setStringValue(raw);
|
||||
}
|
||||
}
|
||||
valueDTO.setFieldId(chartViewFieldDTO.getId());
|
||||
valueDTO.setValue(value);
|
||||
dynamicLabelValue.add(valueDTO);
|
||||
}
|
||||
}
|
||||
@@ -1643,9 +1661,15 @@ public class ChartDataBuild {
|
||||
for (int ii = 0; ii < view.getExtTooltip().size(); ii++) {
|
||||
DynamicValueDTO valueDTO = new DynamicValueDTO();
|
||||
ChartViewFieldDTO chartViewFieldDTO = view.getExtTooltip().get(ii);
|
||||
BigDecimal value = StringUtils.isEmpty(row[ii + (size - extSize) + view.getExtLabel().size()]) ? null : new BigDecimal(row[ii + (size - extSize) + view.getExtLabel().size()]);
|
||||
String raw = row[ii + (size - extSize) + view.getExtLabel().size()];
|
||||
if (StringUtils.isNotEmpty(raw)) {
|
||||
try {
|
||||
valueDTO.setValue(new BigDecimal(raw));
|
||||
} catch (NumberFormatException e) {
|
||||
valueDTO.setStringValue(raw);
|
||||
}
|
||||
}
|
||||
valueDTO.setFieldId(chartViewFieldDTO.getId());
|
||||
valueDTO.setValue(value);
|
||||
dynamicTooltipValue.add(valueDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +205,11 @@ const COUNT_AGGREGATION_TYPE = [
|
||||
]
|
||||
const COUNT_DE_TYPE = [0, 1, 5]
|
||||
|
||||
// 当前选中的指标是否为非数值类型,非数值类型禁用数值格式配置
|
||||
const isNonNumericFormatter = computed(() => {
|
||||
return COUNT_DE_TYPE.includes(curSeriesFormatter.value?.deType)
|
||||
})
|
||||
|
||||
const aggregationList = computed(() => {
|
||||
if (COUNT_DE_TYPE.includes(curSeriesFormatter.value?.deType)) {
|
||||
return COUNT_AGGREGATION_TYPE
|
||||
@@ -851,7 +856,7 @@ onMounted(() => {
|
||||
>
|
||||
<el-select
|
||||
size="small"
|
||||
:disabled="!curSeriesFormatter.show"
|
||||
:disabled="!curSeriesFormatter.show || isNonNumericFormatter"
|
||||
style="width: 100%"
|
||||
:effect="props.themes"
|
||||
v-model="curSeriesFormatter.formatterCfg.type"
|
||||
@@ -873,7 +878,7 @@ onMounted(() => {
|
||||
>
|
||||
<el-input-number
|
||||
controls-position="right"
|
||||
:disabled="!curSeriesFormatter.show"
|
||||
:disabled="!curSeriesFormatter.show || isNonNumericFormatter"
|
||||
style="width: 100%"
|
||||
:effect="props.themes"
|
||||
v-model="curSeriesFormatter.formatterCfg.decimalCount"
|
||||
@@ -895,7 +900,9 @@ onMounted(() => {
|
||||
>
|
||||
<el-select
|
||||
:disabled="
|
||||
!curSeriesFormatter.show || curSeriesFormatter.formatterCfg.type == 'percent'
|
||||
!curSeriesFormatter.show ||
|
||||
isNonNumericFormatter ||
|
||||
curSeriesFormatter.formatterCfg.type == 'percent'
|
||||
"
|
||||
size="small"
|
||||
:effect="themes"
|
||||
@@ -923,7 +930,9 @@ onMounted(() => {
|
||||
>
|
||||
<el-select
|
||||
:disabled="
|
||||
!curSeriesFormatter.show || curSeriesFormatter.formatterCfg.type == 'percent'
|
||||
!curSeriesFormatter.show ||
|
||||
isNonNumericFormatter ||
|
||||
curSeriesFormatter.formatterCfg.type == 'percent'
|
||||
"
|
||||
:effect="props.themes"
|
||||
v-model="curSeriesFormatter.formatterCfg.unit"
|
||||
@@ -949,7 +958,7 @@ onMounted(() => {
|
||||
:class="'form-item-' + themes"
|
||||
>
|
||||
<el-input
|
||||
:disabled="!curSeriesFormatter.show"
|
||||
:disabled="!curSeriesFormatter.show || isNonNumericFormatter"
|
||||
:effect="props.themes"
|
||||
v-model="curSeriesFormatter.formatterCfg.suffix"
|
||||
maxlength="30"
|
||||
@@ -965,7 +974,7 @@ onMounted(() => {
|
||||
|
||||
<el-form-item class="form-item" :class="'form-item-' + themes">
|
||||
<el-checkbox
|
||||
:disabled="!curSeriesFormatter.show"
|
||||
:disabled="!curSeriesFormatter.show || isNonNumericFormatter"
|
||||
size="small"
|
||||
:effect="props.themes"
|
||||
v-model="curSeriesFormatter.formatterCfg.thousandSeparator"
|
||||
|
||||
@@ -423,7 +423,10 @@ export class MultiScatter extends G2PlotChartView<ScatterOptions, G2Scatter> {
|
||||
datum.dynamicTooltipValue?.forEach(item => {
|
||||
const formatter = formatterMap[item.fieldId]
|
||||
if (formatter) {
|
||||
const value = valueFormatter(parseFloat(item.value), formatter.formatterCfg)
|
||||
const value =
|
||||
item.value != null
|
||||
? valueFormatter(parseFloat(item.value), formatter.formatterCfg)
|
||||
: item.stringValue ?? ''
|
||||
const name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName
|
||||
result.push({ color: 'grey', name, value, marker: true })
|
||||
}
|
||||
|
||||
@@ -307,7 +307,10 @@ export function getMultiSeriesTooltip(chart: Chart) {
|
||||
head.data.dynamicTooltipValue?.forEach(item => {
|
||||
const formatter = formatterMap[item.fieldId]
|
||||
if (formatter) {
|
||||
const value = valueFormatter(parseFloat(item.value), formatter.formatterCfg)
|
||||
const value =
|
||||
item.value != null
|
||||
? valueFormatter(parseFloat(item.value), formatter.formatterCfg)
|
||||
: item.stringValue ?? ''
|
||||
const name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName
|
||||
result.push({ color: 'grey', name, value })
|
||||
}
|
||||
@@ -1028,7 +1031,10 @@ export function configL7Tooltip(chart: Chart): TooltipOptions {
|
||||
head.dynamicTooltipValue?.forEach(item => {
|
||||
const formatter = formatterMap[item.fieldId]
|
||||
if (formatter) {
|
||||
const value = valueFormatter(parseFloat(item.value), formatter.formatterCfg)
|
||||
const value =
|
||||
item.value != null
|
||||
? valueFormatter(parseFloat(item.value), formatter.formatterCfg)
|
||||
: item.stringValue ?? ''
|
||||
const name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName
|
||||
result.push({ color: 'grey', name, value: `${value ?? ''}` })
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ public class DynamicValueDTO {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long fieldId;
|
||||
private BigDecimal value;
|
||||
private String stringValue;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ChartDataUtil {
|
||||
|
||||
public static List<String[]> customSort(List<String> custom, List<String[]> data, int index) {
|
||||
List<String[]> res = new ArrayList<>();
|
||||
|
||||
|
||||
// 数据行在自定义排序的范围内,记录该数据行的内容以及下标
|
||||
List<Integer> indexInCustomSort = new ArrayList<>();
|
||||
List<String[]> dataInCustomSort = new ArrayList<>();
|
||||
@@ -271,9 +271,15 @@ public class ChartDataUtil {
|
||||
for (int ii = 0; ii < view.getExtLabel().size(); ii++) {
|
||||
DynamicValueDTO valueDTO = new DynamicValueDTO();
|
||||
ChartViewFieldDTO chartViewFieldDTO = view.getExtLabel().get(ii);
|
||||
BigDecimal value = StringUtils.isEmpty(row[ii + (size - extSize)]) ? null : new BigDecimal(row[ii + (size - extSize)]);
|
||||
String raw = row[ii + (size - extSize)];
|
||||
if (StringUtils.isNotEmpty(raw)) {
|
||||
try {
|
||||
valueDTO.setValue(new BigDecimal(raw));
|
||||
} catch (NumberFormatException e) {
|
||||
valueDTO.setStringValue(raw);
|
||||
}
|
||||
}
|
||||
valueDTO.setFieldId(chartViewFieldDTO.getId());
|
||||
valueDTO.setValue(value);
|
||||
dynamicLabelValue.add(valueDTO);
|
||||
}
|
||||
}
|
||||
@@ -281,9 +287,15 @@ public class ChartDataUtil {
|
||||
for (int ii = 0; ii < view.getExtTooltip().size(); ii++) {
|
||||
DynamicValueDTO valueDTO = new DynamicValueDTO();
|
||||
ChartViewFieldDTO chartViewFieldDTO = view.getExtTooltip().get(ii);
|
||||
BigDecimal value = StringUtils.isEmpty(row[ii + (size - extSize) + view.getExtLabel().size()]) ? null : new BigDecimal(row[ii + (size - extSize) + view.getExtLabel().size()]);
|
||||
String raw = row[ii + (size - extSize) + view.getExtLabel().size()];
|
||||
if (StringUtils.isNotEmpty(raw)) {
|
||||
try {
|
||||
valueDTO.setValue(new BigDecimal(raw));
|
||||
} catch (NumberFormatException e) {
|
||||
valueDTO.setStringValue(raw);
|
||||
}
|
||||
}
|
||||
valueDTO.setFieldId(chartViewFieldDTO.getId());
|
||||
valueDTO.setValue(value);
|
||||
dynamicTooltipValue.add(valueDTO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user