[geoChart] legend - localize legend numbers, change decimal separator.

414 views
Skip to first unread message

Alvaro Fernández Seco

unread,
May 21, 2015, 6:18:33 AM5/21/15
to google-visua...@googlegroups.com
Hello,

I have a geoChart embedded in a web page where number formatting is taking into account the current locale.

I want to use a different decimal separator simbol in geoChart legend, for instance:

locale                                                                 legend
     es                          25,89 [gradient rect legend] 68,78
     en                          25.89 [gradient rect legend] 68.78

I've been trying to achieve this using legend.numberFormat on geoChart options, but it expects a string... and there is no way to set decimal symbol. 

I was hoping to use there something like a google.visualization.NumberFormat({decimalSymbol: ','}) object but it doesn't work.

I am able to achive this behaviour listening for ready event on geoChart and updating all svg > text tags using something like $('#your-geo-chart-div svg text').text().replace('.', ',').

But whenever a click/mouseover event is fired over the geoChart it seems that the full legend is destroyed and re-recreated again... so it only works for first rendering. 

Did anyone encountered this problem before? Any tips or ideas on how to get this working will be highly appreciated. 

Regards,
Alvaro.


Sergey Grabkovsky

unread,
May 21, 2015, 9:36:31 AM5/21/15
to google-visua...@googlegroups.com
Hi Alvaro,

You can automatically have the GeoChart use the right locale by specifying the 'language' parameter to google.load. Here is an example of that: http://jsfiddle.net/brw4gj21/

Alternatively, you could specify a pattern like '#,##', which would effectively replace the decimal separator. I think the ICU format is flexible enough to do what you want.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Alvaro Fernández Seco

unread,
May 21, 2015, 11:07:20 AM5/21/15
to google-visua...@googlegroups.com
Hi Sergey,

using 'language' parameter when calling google.load did the trick.

I also tried with ICU formats, but I'm unable to change decimal separator only by using ICU patterns. For instance, when language is 'en' I am unable to get ',' as decimal separator only by using ICU: http://jsfiddle.net/brw4gj21/2/

Thanks a lot for your time,
Regards.

El jueves, 21 de mayo de 2015, 15:36:31 (UTC+2), Sergey escribió:
Hi Alvaro,

You can automatically have the GeoChart use the right locale by specifying the 'language' parameter to google.load. Here is an example of that: http://jsfiddle.net/brw4gj21/

Alternatively, you could specify a pattern like '#,##', which would effectively replace the decimal separator. I think the ICU format is flexible enough to do what you want.

On Thu, May 21, 2015 at 6:18 AM Alvaro Fernández Seco <alvaro...@gmail.com> wrote:
Hello,

I have a geoChart embedded in a web page where number formatting is taking into account the current locale.

I want to use a different decimal separator simbol in geoChart legend, for instance:

locale                                                                 legend
     es                          25,89 [gradient rect legend] 68,78
     en                          25.89 [gradient rect legend] 68.78

I've been trying to achieve this using legend.numberFormat on geoChart options, but it expects a string... and there is no way to set decimal symbol. 

I was hoping to use there something like a google.visualization.NumberFormat({decimalSymbol: ','}) object but it doesn't work.

I am able to achive this behaviour listening for ready event on geoChart and updating all svg > text tags using something like $('#your-geo-chart-div svg text').text().replace('.', ',').

But whenever a click/mouseover event is fired over the geoChart it seems that the full legend is destroyed and re-recreated again... so it only works for first rendering. 

Did anyone encountered this problem before? Any tips or ideas on how to get this working will be highly appreciated. 

Regards,
Alvaro.


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages