Number formatting


#1

Hey guys i have an interesting question for my charts I need to render numbers using period ( . ) as a separator for thousands and comma ( , ) for decimals rather than the other way around, there is a config for that in the toolkit?


#2

Hey actually there is a way to do that using the provider metadata config, you just need to do something like this:

var providers = [ {
        name:'Elasticsearch',
        provider:'elasticsearch',
        url:'https://myproviderurl.com',
        metadata: {
            'my_source': {
                'fields': {
                    'my_number_field': {
                        type: 'NUMBER',
                        displayFormat: ‘0.0,00’
                    },
                    'my_money_field': {
                        type: 'MONEY',
                        displayFormat: ‘0.0,00 $’
                    }
                }
            }
        }
    }
]

Look at the displayFormat config that is the key for solve your problem and also take a look at this link: https://chartfactor.com/doc/latest/data_providers/custom_metadata/#custom-formats-for-numeric-fields


#3

I Tried this but it is still using the comma as a thousands separator, i follow te instructions in the documentation, maybe Am i doing something wrong?, or maybe depends on my data?


#4

I see, my bad, i forget to use a special character in the config, let show you:

var providers = [ {
        name:'Elasticsearch',
        provider:'elasticsearch',
        url:'https://myproviderurl.com',
        metadata: {
            'my_source': {
                'fields': {
                    'my_number_field': {
                        type: 'NUMBER',
                        displayFormat: ‘0.0,00 i’
                    },
                    'my_money_field': {
                        type: 'MONEY',
                        displayFormat: ‘0.0,00 $i’
                    }
                }
            }
        }
    }
]

The i character is making the magic things, so you can see also in the documentation.


#5

You have the reason now it works, thank you so much, i really need this :grinning: