Closed Jorge-hercas closed 10 months ago
I tried using a JS function and it works, but im not sure how I can make the label only shows the value of "cyl". My code is:
mtcars |>
tibble::rownames_to_column("model") |>
e_charts(model)|>
e_bar(cyl) |>
e_labels(formatter = htmlwidgets::JS("function(params) {
var total = params.data.length;
var step = 3;
if ((params.dataIndex + 1) % step !== 0) {
return '';
}else{
return params.value;
}
}
"), rotate = 90, position = "inside")
@Jorge-hercas My approach would be not using formatter but doing it like this with the help of e_add_nested()
:
library(echarts4r)
library(dplyr)
df <- mtcars |>
tibble::rownames_to_column("model") |> arrange(model)
df$show <- rep(c(TRUE, FALSE, FALSE),
length.out = nrow(df))
df |>
e_charts(model) |>
e_bar(cyl, label = list(position = "insideTop")) |>
e_add_nested("label", show) |>
e_legend(F)
Does the output look like the chart you were looking for?
Closing because of inactivity
Hi and thanks for reading me. Im working on a echarts plot in R and I want to show the label of the vars but only in every 2 or 3 bars, because i don't want it to look too saturated with information
I haven't found a working argument to e_labels(), could you help me? please
My code is the following: