在echarts4r中显示标签百分比

ehxuflar  于 2023-04-03  发布在  Echarts
关注(0)|答案(1)|浏览(242)
df1 <- data.frame(Date = c(1,2,3),
                  Reach = c(12,15,20),
                  Cost = c(0.98,0.00056,0.89))

df1 %>% 
  e_chart(Date) %>% 
  e_bar(Reach, label = list(show = FALSE)) %>% 
  e_line(Cost, y_index = 1, label = list(show = TRUE), scales = list(x = list(label = scales::percent_format(scale = 1)))) %>%
  e_tooltip() %>% 
  e_title("Actual v CPC")

因此,我尝试使用echarts 4 r显示此代码来显示条形图和折线图,然后我想显示e_line标签,但不是e_bar,它已经与此代码一起工作,但因为我想显示e_line标签的百分比,我使用刻度或{d}%在e_line格式化程序中,但它仍然不工作。我也尝试使用e_labels,但我不能隐藏条形标签

ax6ht2ek

ax6ht2ek1#

一种选择是使用一个小的JS格式化程序函数,如下所示:

library(echarts4r)
library(magrittr)

df1 %>%
  e_chart(Date) %>%
  e_bar(Reach, label = list(show = FALSE)) %>%
  e_line(Cost, y_index = 1, 
         label = list(
           show = TRUE, 
           formatter = htmlwidgets::JS(
             "(params) => params.value[1] + ' %';")
    )) %>%
  e_tooltip() %>%
  e_title("Actual v CPC")

相关问题