From 631cf7940e1b02436441b73d0a762b93ffc5d2cb Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Tue, 28 Jun 2022 10:28:39 -0300 Subject: [PATCH] add milhar separator graphs --- src/components/graph/Chart.tsx | 11 ++++++++++- src/components/graph/LineBarChart2.tsx | 12 ++++++++++-- src/components/graph/SingleBar.tsx | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/graph/Chart.tsx b/src/components/graph/Chart.tsx index 941977c..6d9c8b3 100644 --- a/src/components/graph/Chart.tsx +++ b/src/components/graph/Chart.tsx @@ -49,7 +49,16 @@ export default function Chart({ title, data1, data2, label, subtitle, dataset1, datalabels: { display: true, color: barLabel? 'black' : "rgba(255, 255, 255, 0)", - formatter: Math.round, + formatter: (value, ctx) => { + let sum = 0; + const dataArr = ctx.chart.data.datasets[0].data; + dataArr.map(data => { + sum += data; + }); + const result = `${parseFloat(value).toLocaleString('pt-br')}` + + return value==null? null : result + }, anchor: "end", offset: -20, align: "start", diff --git a/src/components/graph/LineBarChart2.tsx b/src/components/graph/LineBarChart2.tsx index 273fe77..ad9efea 100644 --- a/src/components/graph/LineBarChart2.tsx +++ b/src/components/graph/LineBarChart2.tsx @@ -78,7 +78,6 @@ export function LineBarChart2({ title, subtitle, data1, data2, data3, label, red const currentTime = new Date(); - const labels = label const options: any = { @@ -88,12 +87,21 @@ export function LineBarChart2({ title, subtitle, data1, data2, data3, label, red display: true, color: barLabel? 'black' : "rgba(255, 255, 255, 0)", // backgroundColor: '#255488', - formatter: Math.round, anchor: "end", offset: -20, align: "start", font: { size: 12 + }, + formatter: (value, ctx) => { + let sum = 0; + const dataArr = ctx.chart.data.datasets[0].data; + dataArr.map(data => { + sum += data; + }); + const result = `${parseFloat(value).toLocaleString('pt-br')}` + + return value==null? null : result } }, legend: { diff --git a/src/components/graph/SingleBar.tsx b/src/components/graph/SingleBar.tsx index 2fec803..da7c3f9 100644 --- a/src/components/graph/SingleBar.tsx +++ b/src/components/graph/SingleBar.tsx @@ -46,7 +46,7 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, barLabel sum += data; }); const percentage = (dataProps[ctx.dataIndex].econ_percentual*100).toFixed(0)+"%"; - const result = `${parseFloat(value).toFixed(0)}\n ${percentage}` + const result = `${parseFloat(value).toLocaleString('pt-br')}\n ${percentage}` return value==null? null : result },