简体   繁体   English

Highcharter / Highmap:将图例标签格式更改数十亿个

[英]Highcharter/Highmap: change legend label format for billions

I would like to change the label format of the legend in a highcharter map. 我想在高章程地图中更改图例的标签格式。 I have values ranging from 0 to 200 billion. 我的值从0到2000亿不等。 The first steps, ie thousand (k) and million (M), are fine, but I need to change the abbreviation for billion "G". 第一步(即千(k)和百万(M))很好,但是我需要更改十亿“ G”的缩写。

I am not really good in javascript, hence I dont know how to write the format-command in the hc_legend() function to change the "G" to a "B", while leaving "k" for thousand and "M" for million. 我的Java语言不是很好,因此我不知道如何在hc_legend()函数中编写format-command来将“ G”更改为“ B”,而将“ k”保留为千,“ M”保留为百万。 。

Here is a small example where one can see that highcharter uses "G" for billions. 这是一个小例子,您可以看到高章程使用数十亿的“ G”。

library(highcharter)

df = data.frame(
  Country = c("AT","BE","CH","DE","FR","IT"),
  variable = rnorm(n = 6, mean = 120000000000, sd = 20000000000)
)


hcmap(map = "custom/europe",
      data = df, joinBy = c("hc-a2", "Country"), value = "variable", name = "variable",
      dataLabels = list(enabled = TRUE, format = '{point.name}'),
      borderColor = "#FAFAFA", borderWidth = 0.1,
      tooltip = list(valueDecimals = 0, valuePrefix = "€", valueSuffix = "")) %>%
  hc_mapNavigation(enabled = TRUE)
  #hc_legend(enabled = TRUE, format = "{value}B") #basically a placeholder, as I dont know how to proceed

Changing the 'G' to 'B' has to be done as follows: 将“ G”更改为“ B”必须执行以下操作:

hcoptslang <- getOption("highcharter.lang")
hcoptslang$numericSymbols <-c( "k", "M", "B" ,"T", "P" ,"E")
options(highcharter.lang = hcoptslang)

By that you change the numberic Symbols for highcharter. 这样,您就可以更改高位符号的数字符号。

PS: Thanks to @wergeld and @Roman Luštrik for their directions. PS:感谢@wergeld和@RomanLuštrik的指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM