I'm trying to make plot with extra variables in tooltips, but can't understand how to make it.
For example I want to display qsec, cyl and hp columns
Tutorial from API didn't help me
Example :
library(dplyr)
library(echarts4r)
mtcars %>%
tibble::rownames_to_column("model") %>%
e_charts(wt) %>%
e_scatter(mpg,bind=model) %>%
e_tooltip(formatter = htmlwidgets::JS("
function(params){
return('<strong>' + params.name +
'</strong><br />wt: ' + params.value[0] +
'<br />mpg: ' + params.value[1] +
'<br />qsec: ' + this.qsec ) } "))
expected result something like this:
https://github.com/jbkunst/highcharter/issues/54
A bit hacky, but you can pass in a string with the data you wish to display as the data name, then parse it inside the function. For example,
mtcars %>%
tibble::rownames_to_column("model") %>%
mutate(model = paste(model, qsec, sep = ",")) %>%
e_charts(wt) %>%
e_scatter(mpg, bind = model) %>%
e_tooltip(formatter = htmlwidgets::JS("
function(params){
var vals = params.name.split(',')
return('<strong>' + vals[0] +
'</strong><br />wt: ' + params.value[0] +
'<br />mpg: ' + params.value[1]) +
'<br />qsec: ' + vals[1]} "))
which gives you

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With