JohnCoene / echarts4r

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

Customising tooltips in echars4rBox #297

Open domsle opened 3 years ago

domsle commented 3 years ago

Hello,

Is it possible to customize tooltips in boxes?

I have tried with setting argument tooltip with a formatter function:

    output$box1 <- renderEcharts4rBox({
        echarts4rBox(cars, 
                     speed, 
                     dist, 
                     "Cake", 
                     type = "bar",
                     tooltip = list(formatter = htmlwidgets::JS("
                     function(params){
                     return('wt: ' + params.value[0] + '<br />mpg: ' + params.value[1])
                     }"
                     )))
    })

But the result is, instead of the js function being executed, it is just printed:

image

Is it possible to do?

JohnCoene commented 3 years ago

Ah, boxes are not actual {htmlwidgets}, I thought it was smart to bypass all of this for these... perhaps it was not. I will have to think of a solution.

The tooltip can still be customised but executable JavaScript code (e.g.: functions passed with JS()) will not work. Sorry.

domsle commented 3 years ago

Could you please show a simple example of how I could customize it? Let's say I just want to show some basic description of what x and y axis values mean.

czw., 25 mar 2021, 21:29 użytkownik John (JP) Coene < @.***> napisał:

Ah, boxes are not actual {htmlwidgets}, I thought it was smart to bypass all of this for these... perhaps it was not. I will have to think of a solution.

The tooltip can still be customised but executable JavaScript code (e.g.: functions passed with JS()) will not work. Sorry.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JohnCoene/echarts4r/issues/297#issuecomment-807428002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AENTA5ZZ5GN46KTQTYXK7FTTFOMJTANCNFSM4ZXI7T7A .

swsoyee commented 3 years ago

I've been trying to solve this problem for several hours, including putting the evaluate function into box-binding.js to handle the problem of the parameter being a function. But unfortunately I found that I couldn't pass the function as an argument in the box anyway.

So it seems that there is no way to customize tooptip with functions yet.