support displaying data in percentage format

This commit is contained in:
MaysWind
2026-04-15 22:21:42 +08:00
parent 50472d437a
commit c64c60c6a0
4 changed files with 38 additions and 3 deletions
+14 -1
View File
@@ -32,6 +32,7 @@ export interface CommonPieChartProps {
colorField?: string; colorField?: string;
hiddenField?: string; hiddenField?: string;
amountValue?: boolean; amountValue?: boolean;
percentValue?: boolean;
defaultCurrency?: string; defaultCurrency?: string;
showValue?: boolean; showValue?: boolean;
showPercent?: boolean; showPercent?: boolean;
@@ -81,7 +82,7 @@ export function usePieChartBase(props: CommonPieChartProps) {
accumulatedPaintPercent += finalItem.paintPercent; accumulatedPaintPercent += finalItem.paintPercent;
finalItem.displayPercent = formatPercentToLocalizedNumerals(finalItem.percent, 2, '<0.01'); finalItem.displayPercent = formatPercentToLocalizedNumerals(finalItem.percent, 2, '<0.01');
finalItem.displayValue = props.amountValue ? formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency) : formatNumberToLocalizedNumerals(value, 2); finalItem.displayValue = getDisplayValue(value);
validItems.push(finalItem); validItems.push(finalItem);
} }
@@ -94,6 +95,18 @@ export function usePieChartBase(props: CommonPieChartProps) {
return validItems; return validItems;
}); });
function getDisplayValue(value: number): string {
if (props.percentValue) {
return formatPercentToLocalizedNumerals(value, 2, '<0.01');
}
if (props.amountValue) {
return formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency);
}
return formatNumberToLocalizedNumerals(value, 2);
}
watch(() => props.items, () => { watch(() => props.items, () => {
selectedIndex.value = 0; selectedIndex.value = 0;
}); });
+7 -1
View File
@@ -34,6 +34,7 @@ const props = defineProps<{
translateName?: boolean; translateName?: boolean;
valueTypeName: string; valueTypeName: string;
amountValue?: boolean; amountValue?: boolean;
percentValue?: boolean;
defaultCurrency?: string; defaultCurrency?: string;
}>(); }>();
@@ -43,7 +44,8 @@ const {
tt, tt,
getCurrentLanguageTextDirection, getCurrentLanguageTextDirection,
formatAmountToLocalizedNumeralsWithCurrency, formatAmountToLocalizedNumeralsWithCurrency,
formatNumberToLocalizedNumerals formatNumberToLocalizedNumerals,
formatPercentToLocalizedNumerals
} = useI18n(); } = useI18n();
const textDirection = computed<TextDirection>(() => getCurrentLanguageTextDirection()); const textDirection = computed<TextDirection>(() => getCurrentLanguageTextDirection());
@@ -249,6 +251,10 @@ function getItemName(name: string): string {
} }
function getDisplayValue(value: number): string { function getDisplayValue(value: number): string {
if (props.percentValue) {
return formatPercentToLocalizedNumerals(value, 2, '<0.01');
}
if (props.amountValue) { if (props.amountValue) {
return formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency); return formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency);
} }
+14 -1
View File
@@ -38,6 +38,7 @@ const props = defineProps<{
colorField?: string; colorField?: string;
hiddenField?: string; hiddenField?: string;
amountValue?: boolean; amountValue?: boolean;
percentValue?: boolean;
defaultCurrency?: string; defaultCurrency?: string;
showValue?: boolean; showValue?: boolean;
showPercent?: boolean; showPercent?: boolean;
@@ -84,7 +85,7 @@ const radarData = computed<RadarChartData>(() => {
const finalPercent = (isNumber(percent) && percent >= 0) ? percent : (value > 0 ? value / totalValidValue * 100 : 0); const finalPercent = (isNumber(percent) && percent >= 0) ? percent : (value > 0 ? value / totalValidValue * 100 : 0);
const displayPercent = formatPercentToLocalizedNumerals(finalPercent, 2, '<0.01'); const displayPercent = formatPercentToLocalizedNumerals(finalPercent, 2, '<0.01');
const displayValue = props.amountValue ? formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency) : formatNumberToLocalizedNumerals(value, 2); const displayValue = getDisplayValue(value);
indicators.push({ indicators.push({
name: name, name: name,
@@ -189,6 +190,18 @@ const chartOptions = computed<object>(() => {
] : [] ] : []
}; };
}); });
function getDisplayValue(value: number): string {
if (props.percentValue) {
return formatPercentToLocalizedNumerals(value, 2, '<0.01');
}
if (props.amountValue) {
return formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency);
}
return formatNumberToLocalizedNumerals(value, 2);
}
</script> </script>
<style scoped> <style scoped>
@@ -93,6 +93,7 @@
:show-percent="true" :show-percent="true"
:enable-click-item="true" :enable-click-item="true"
:amount-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isAmount" :amount-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isAmount"
:percent-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isPercent"
:default-currency="defaultCurrency" :default-currency="defaultCurrency"
id-field="id" id-field="id"
name-field="name" name-field="name"
@@ -121,6 +122,7 @@
:show-value="true" :show-value="true"
:show-percent="true" :show-percent="true"
:amount-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isAmount" :amount-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isAmount"
:percent-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isPercent"
:default-currency="defaultCurrency" :default-currency="defaultCurrency"
name-field="name" name-field="name"
value-field="totalAmount" value-field="totalAmount"
@@ -179,6 +181,7 @@
:items="seriesDimensionTransactionExplorerData" :items="seriesDimensionTransactionExplorerData"
:value-type-name="tt(TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.name ?? 'Value')" :value-type-name="tt(TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.name ?? 'Value')"
:amount-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isAmount" :amount-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isAmount"
:percent-value="TransactionExplorerValueMetric.valueOf(currentExplorer.valueMetric)?.isPercent"
:default-currency="defaultCurrency" :default-currency="defaultCurrency"
name-field="name" name-field="name"
values-field="categoryValues" values-field="categoryValues"