Malta
Malta

Reputation: 1983

In R plotly d3js how to format a number with space instead of comma?

I am working with R plotly which is based on d3js, and would like to format axis ticks. I saw I have to use the "tickformat" option in layout, which has to be set using the syntax described here : https://github.com/d3/d3-format/blob/master/README.md#locale_format but I can't get to change the grouping symbol (the thousand separator) : it's a comma and would like it to be a space.

By default, I get number formatted like this :

1500

I can get them formatted like this :

1,500 

by using tickformat=",", but I would like to format like that :

1 500 

Any idea ?

Upvotes: 4

Views: 1100

Answers (1)

user2195252
user2195252

Reputation: 99

I know this is an old question but still answering in case other people could benefit from it.

You can use the comma as thousand separator and add the locale in your graph.

For example in Python, if you would like to have an Indicator that displays the number with a space as thousand separator, you could do the following:

go.Indicator(
 mode = "number",
 value = num_value,
 number = {
  'font.size': 45,
  "valueformat": ","
},

And in the Graph object, you can add the following:

dcc.Graph(id="something", config=dict(locale="fr")

Upvotes: 1

Related Questions