Skip to content

Commit

Permalink
CustomTooltipItem
Browse files Browse the repository at this point in the history
  • Loading branch information
wkrzywiec committed Nov 30, 2024
1 parent 4e36d47 commit 5018623
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion services/mankkoo-ui/components/charts/Piechart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export interface PieChartData {
data: number[]
}

interface CustomTooltipItem extends TooltipItem<'pie'> {
_metasets : [{
total: number
}]
}


export default function PieChart({
input={data: [30, 50, 20], labels: ['Red','Black','Blue']},
size=1 } : { input?: PieChartData, size?: number}) {
Expand Down Expand Up @@ -48,8 +55,10 @@ export default function PieChart({
callbacks: {
label: function(context) {
console.log(context.chart)
const chart = context.chart as unknown as TooltipItem<"pie">

const currentValue: number = context.raw as number

const chart = context.chart as CustomTooltipItem
const total: number = chart._metasets[context.datasetIndex].total

const percentage = (currentValue/total * 100).toFixed(1);
Expand Down

0 comments on commit 5018623

Please sign in to comment.