amcharts / amcharts4

The most advanced amCharts charting library for JavaScript and TypeScript apps.
https://www.amcharts.com/
1.16k stars 322 forks source link

Comma instead of dot(tooltip) #4332

Closed PedroHGaspar closed 1 year ago

PedroHGaspar commented 1 year ago

Hey guys, i've tried all this tutorials from the DOCS but non of them seems to work properly in my code (probably i'm doing something wrong). I'm trying to change the dot for the comma in the tooltips, but nothing happens...

This is the DOCS I've searched: https://www.amcharts.com/docs/v4/concepts/formatters/formatting-numbers/ https://www.amcharts.com/docs/v4/reference/numberformatter/ https://www.amcharts.com/docs/v4/concepts/formatters/

This is my code:

function graficoAtribuicaoPerformance(dados) {

    atribuicaoPerformance.valores = dados;

    var dadosIniciais = dados["3m"];
    atribuicaoPerformance.data = dadosIniciais;

    var categoryAxis = atribuicaoPerformance.xAxes.push(new am4charts.CategoryAxis());
    categoryAxis.dataFields.category = "category";
    categoryAxis.renderer.grid.template.location = 0;
    categoryAxis.renderer.minGridDistance = 30;
    categoryAxis.renderer.ticks.template.disabled = true;
    categoryAxis.renderer.ticks.template.strokeOpacity = 0.5;
    categoryAxis.renderer.labels.template.rotation = -35;
    categoryAxis.renderer.labels.template.horizontalCenter = "right";

    categoryAxis.renderer.grid.template.disabled = true;

    categoryAxis.fontFamily = "Lato 700";
    categoryAxis.fontSize = 12;
    categoryAxis.fontWeight = 700;
    categoryAxis.renderer.labels.template.fill = am4core.color("#8D9297");

    var valueAxis = atribuicaoPerformance.yAxes.push(new am4charts.ValueAxis());
    valueAxis.calculateTotals = true;

    valueAxis.renderer.grid.template.disabled = true;

    valueAxis.fontFamily = "Lato 700";
    valueAxis.fontSize = 12;
    valueAxis.fontWeight = 700;
    valueAxis.renderer.labels.template.fill = am4core.color("#BABFC5");

    function createSeries(open, close, showSum) {
        var series = atribuicaoPerformance.series.push(new am4charts.ColumnSeries());
        series.dataFields.valueY = close;
        series.dataFields.openValueY = open;
        series.dataFields.categoryX = "category";
        series.clustered = false;
        series.columns.template.column.cornerRadiusTopRight = 5;
        series.columns.template.column.cornerRadiusTopLeft = 5;
        series.strokeWidth = 0;
        series.columns.template.width = am4core.percent(90);
        series.fill = am4core.color("#012837");

        series.columns.template.tooltipText = `[bold]{category}[/]\nAbertura: {open.formatNumber('#.##')}\nFechamento: {close.formatNumber('#.##')} [/]\nValor: {value.formatNumber('#.##')}`;

        //formatNumber é uma funçao do amcharts para formatar numeros em tooltip

        if (showSum) {
            var sumBullet = series.bullets.push(new am4charts.LabelBullet());
            sumBullet.label.text = "{valueY.close}";
            sumBullet.verticalCenter = "bottom";
            sumBullet.dy = -8;
            sumBullet.label.adapter.add("text", function(text, target) {
                var val = Math.abs(target.dataItem.dataContext.close2 - target.dataItem.dataContext.open1);
                return val;
            });
        }
    }

}

In this code i've wrote this: series.columns.template.tooltipText = [bold]{category}[/]\nAbertura: {open.formatNumber('#.##')}\nFechamento: {close.formatNumber('#.##')} [/]\nValor: {value.formatNumber('#.##')};

I've already tried to take off the format.number and leave just the {open}, {close} and {value}, but the dot stays. I've already tried to put a replace like this: series.columns.template.tooltipText = [bold]{category}[/]\nAbertura: {open.formatNumber('#.##').replace('.', ',')}\nFechamento: {close.formatNumber('#.##').replace('.', ',')} [/]\nValor: {value.formatNumber('#.##').replace('.', ',')};

i've also tried to put the localeToString but nothing happens either: series.columns.template.tooltipText = [bold]{category}[/]\nAbertura: {open.formatNumber('#.##').toLocaleString('pt-BR')}\nFechamento: {close.formatNumber('#.##').toLocaleString('pt-BR')} [/]\nValor: {value.formatNumber('#.##').toLocaleString('pt-BR')};

but nothing happens either, the dot stays on the tooltip. The first printscreen is the first code, and the second printscreen is the seconde code with the replace:

image

image

They still the same thing even with the replace.

martynasma commented 1 year ago

You should probably approach dots/commas in numbers via locale, not formatters: https://www.amcharts.com/docs/v4/concepts/locales/#Numbers

PedroHGaspar commented 1 year ago

You should probably approach dots/commas in numbers via locale, not formatters: https://www.amcharts.com/docs/v4/concepts/locales/#Numbers

It worked! Thank you very much :D

image