antvis / G2Plot

:dango: An interactive and responsive charting library based on G2.
https://g2plot.antv.antgroup.com
MIT License
2.56k stars 607 forks source link

How do I set current culture #3663

Closed true-perfect-code closed 1 year ago

true-perfect-code commented 1 year ago

I use g2plot JS library in Blazor and it works fine. My only problem is that on a German computer I don't get the decimal numbers with comma. The numbers are displayed in English format with a dot, which confuses the user!

I have asked both ChatGPT and Bard about this and they both think that my cultur of JS function should be taken from Blazor. Unfortunately, this statement is not true, because I also use the Ant-Blazor UI component, for example, and there the decimal numbers are displayed correctly in German format with comma. On the other hand, if you look at diagrams, the decimal numbers are displayed there with a dot. So if JS would take the cultur from Blazor, then I would have the correct number format everywhere in the application, right?

My question is, is there anywhere in the JS function where I can set the cultur? My current JS chart function in Blazor looks like this:

function createColumnChart(data_config) {
    var data = data_config.list_data;
    const iscurrency = data_config.isFormatterCurrency
    const plot = new G2Plot.Column(data_config.chartID, {
        data,
        xField: data_config.xField,
        yField: data_config.yField,
        label: {
            position: 'middle',
            style: {
                fill: '#FFFFFF',
                /*opacity: 0.6,*/
            },
        },
        xAxis: {
            label: {
                autoHide: true,
                autoRotate: false,
            },
        },
        meta: {
            [data_config.xField]: {
                alias: data_config.xAlias, // X-Achsenbezeichnung
            },
            [data_config.yField]: {
                alias: data_config.yAlias, // Y-Achsenbezeichnung
                formatter: iscurrency ? (v) => `${v.toFixed(2)} €` : (v) => `${v.toFixed(2)}`,
            },
        },
    });

    plot.render();
}

Thanks pc

true-perfect-code commented 1 year ago

I have solved this problem using: ${v.toFixed(2).replace('.', ',')}