Reputation: 529
I am wanting to customize the popup boxes (I believe called tooltips) on a highcharter chart made in R.
# Packages
library(highcharter)
library(tidyverse)
# Here is the data
fake_dat <- tribble(
~Project_Name, ~Portfolio, ~Lender, ~Loan_Balance, ~Maturity_Year,
"Building_1",'Office','Chase',100000,2021,
"Hotel_1","Hospitality",'Chase',50000,2022,
"Condo_1","Development","Happy Bank",175000,2023,
"Building_2","Office","Bank of America",125000,2024)
# Base chart
fake_dat %>%
hchart("bar",
hcaes(x = Project_Name, y = Loan_Balance),
name = "Loan Balance")
When I drag the mouse over the chart bars, it provides a popup box that includes information for Project Name and Loan Balance fields I specificied.
Is it possible to add additional text for the other fields - Portfolio, Lender, Maturity Year - to display when hovering the mouse over the series?
Upvotes: 1
Views: 794
Reputation: 41220
You could use hc_tooltip
and create a custom JS
formatter.
Graph data is accessible through the this.point.
property.
fake_dat %>%
hchart("bar",
hcaes(x = Project_Name, y = Loan_Balance),
name = "Loan Balance") %>%
hc_tooltip(formatter = JS("function(){
return ('Lender: ' + this.point.Lender + ' <br> Loan balance: ' + this.point.Loan_Balance)
}"))
Upvotes: 2