fix(data-vi): tooltip bug of pie chart (#3745)

This commit is contained in:
YANG QIA 2024-03-18 12:33:03 +08:00 committed by GitHub
parent 3b619682ee
commit 3942b7cb94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
import { G2PlotChart } from './g2plot'; import { G2PlotChart } from './g2plot';
import { Pie as G2Pie } from '@ant-design/plots'; import { Pie as G2Pie } from '@ant-design/plots';
import { ChartType } from '../chart'; import { ChartType, RenderProps } from '../chart';
export class Pie extends G2PlotChart { export class Pie extends G2PlotChart {
constructor() { constructor() {
@ -30,4 +30,19 @@ export class Pie extends G2PlotChart {
}, },
}; };
}; };
getProps({ data, general, advanced, fieldProps }: RenderProps) {
const props = super.getProps({ data, general, advanced, fieldProps });
return {
...props,
tooltip: (d, index: number, data, column: any) => {
const field = column.y0.field;
const props = fieldProps[field];
const name = props?.label || field;
const transformer = props?.transformer;
const value = column.y0.value[index];
return { name, value: transformer ? transformer(value) : value };
},
};
}
} }