I am creating a doughnut chart using echarts4r
. Now I am trying to add a custom tooltip and I am able to replicate the examples given here Echarts4r : Create stacked area chart with percentage from total in tooltip and here Displaying extra variables in tooltips echarts4r. However, I do not really understand how this extends to a pie chart. I would like to have a pie chart with a tooltip that shows both the total and the relative percentage
library(tidyverse)
library(echarts4r)
My_df <- data.frame(n = c(1, 4, 10),
x = c("A", "B", " C")) %>%
mutate(percent = round(n/sum(n), 2) )
My_df %>%
e_charts(x) %>%
e_pie(n, radius = c("50%", "70%")) %>%
e_tooltip()
This is my best shot so far
My_df %>%
e_charts(x) %>%
e_pie(n, radius = c("50%", "70%")) %>%
e_tooltip(formatter = htmlwidgets::JS("
function(params){
return('<strong>' + params.name +
'</strong><br />total: ' + params.value +
'<br />percent: ' + params.value[1]) } "))
in the scatterplot examples the extra values are attached using bind =
but that does not work for the pie chart.