File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
src/Shared/Components/Charts Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ export type ChartProps = {
114114 * @default 'top'
115115 */
116116 placement ?: TooltipProps [ 'placement' ]
117+ datasetValueFormatter ?: ( value : number ) => string | number
117118 }
118119 /** A title for x axis */
119120 xScaleTitle ?: string
Original file line number Diff line number Diff line change @@ -192,7 +192,11 @@ export const getDefaultOptions = ({
192192 yScaleTickFormat,
193193 xScaleTickFormat,
194194 xAxisLabels,
195+ tooltipConfig,
195196 } = chartProps
197+
198+ const { datasetValueFormatter } = tooltipConfig ?? { }
199+
196200 const baseOptions : ChartOptions = {
197201 responsive : true ,
198202 devicePixelRatio : 3 ,
@@ -213,6 +217,16 @@ export const getDefaultOptions = ({
213217 enabled : false ,
214218 position : 'nearest' ,
215219 external : externalTooltipHandler ,
220+ ...( datasetValueFormatter
221+ ? {
222+ callbacks : {
223+ label ( { dataset, raw } ) {
224+ // only number values are expected in raw as input in our types for yAxisValues is number[]
225+ return `${ dataset . label } : ${ datasetValueFormatter ( raw as number ) } `
226+ } ,
227+ } ,
228+ }
229+ : { } ) ,
216230 } ,
217231 } ,
218232 elements : {
You can’t perform that action at this time.
0 commit comments