diff --git a/src/utils/helpers/charts.ts b/src/utils/helpers/charts.ts index 256fc6a9..e702dc09 100644 --- a/src/utils/helpers/charts.ts +++ b/src/utils/helpers/charts.ts @@ -6,7 +6,13 @@ export const pointerOnHover = ({ native }: ChartEvent, [ firstElement ]: ActiveE return; } - (native.target as any).style.cursor = firstElement ? 'pointer' : 'default'; + const canvas = native.target as HTMLCanvasElement; + + canvas.style.cursor = firstElement ? 'pointer' : 'default'; }; -export const renderChartLabel = ({ dataset, label }: TooltipItem) => `${dataset.label}: ${prettify(label)}`; +export const renderChartLabel = ({ dataset, formattedValue }: TooltipItem) => + `${dataset.label}: ${prettify(formattedValue)}`; + +export const renderPieChartLabel = ({ label, formattedValue }: TooltipItem) => + `${label}: ${prettify(formattedValue)}`; diff --git a/src/visits/helpers/DefaultChart.tsx b/src/visits/helpers/DefaultChart.tsx index 21f62ce9..7792aac7 100644 --- a/src/visits/helpers/DefaultChart.tsx +++ b/src/visits/helpers/DefaultChart.tsx @@ -6,7 +6,7 @@ import { Chart, ChartData, ChartDataset, ChartOptions, LegendItem } from 'chart. import { fillTheGaps } from '../../utils/helpers/visits'; import { Stats } from '../types'; import { prettify } from '../../utils/helpers/numbers'; -import { pointerOnHover, renderChartLabel } from '../../utils/helpers/charts'; +import { pointerOnHover, renderChartLabel, renderPieChartLabel } from '../../utils/helpers/charts'; import { HIGHLIGHTED_COLOR, HIGHLIGHTED_COLOR_ALPHA, @@ -149,7 +149,7 @@ const DefaultChart = ( // Do not show tooltip on items with empty label when in a bar chart filter: ({ label }) => !isBarChart || label !== '', callbacks: { - label: renderChartLabel, + label: isBarChart ? renderChartLabel : renderPieChartLabel, }, }, },