JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
593 stars 81 forks source link

Wrapping text in e_tooltip #471

Closed svenb78 closed 1 year ago

svenb78 commented 1 year ago

Hi,

it's me again. :-)

Given the following example:

library("dplyr")
library("echarts4r")

df <- data.frame(
  label = c(
    "This is a long label which should be wrapped for displaying"
    , "This is another label even longer which also should be wrapped"
  )
  , values = c(10, 40)
) %>%
  mutate(wrapped_label = stringr::str_wrap(label, 10))

plot_e <- df %>%
  e_charts(x = wrapped_label) %>%
  e_pie(serie = values) %>%
  e_legend(show = FALSE) %>%
  e_tooltip(trigger = "item")

plot_e

How can I wrap the text within the tooltip? Following the apache docu, I tried textStyle = list(width = 2, overflow = "break") but that did not work.

rdatasculptor commented 1 year ago

I haven't run your example yet (I must admit) but what exactly should the result be, what should the text be doing?

Does it help to use \n in the text perhaps? Something like this: "This is another label\neven longer which\nalso should be wrapped"

svenb78 commented 1 year ago

Running the example takes a minute ... :-)

I work with a data set on natural reserves (WDPA) and need to plot budget spend by reserve name. The data set is large, and the names are long. Adding line breaks manually is neither practicable nor good style.

helgasoft commented 1 year ago

Solution is to use these two together or alone in tooltip: extraCssText= 'white-space:pre-wrap;', confine= TRUE