简体   繁体   中英

HighcharteR : How to add new labels inside slice of pie chart

I want to add new labels on each slice of a pie chart using HighcharteR (Highchart for R).

When a slice is selected, it is highlighted but not the others. I want that each label in slice react the same way too.

I found some post using javascript solution but not with HighcharteR.

Thanx for the clue

在此处输入图像描述

You need to assign a negative distance to the data labels to move the labels inside a pie chart. I suggest that you use % to keep things relative.

Here's an example.

library(highcharter)

df1 <- data.frame(a = c("Piece 1", "Piece 2", "Piece 3"),
                  b = c(10, 20, 40))

highchart() %>% 
  hc_add_series(df1, type = "pie", 
                dataLabels = list(distance = '-30%', # <- this puts labels inside
                                  backgroundColor = "white"),
                hcaes(x = a, y = b))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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