R HighCharter - 自定义工具提示标题
R HighCharter - customize tool tip captions
我想在用 R 制作的 highcharter 图表上自定义弹出框(我相信称为工具提示)。
# 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")
当我将鼠标拖到图表条上时,它会提供一个弹出框,其中包含我指定的项目名称和贷款余额字段的信息。
是否可以为其他字段添加额外的文本 - 投资组合、贷款人、到期年 - 将鼠标悬停在系列上时显示?
您可以使用 hc_tooltip
并创建自定义 JS
格式化程序。
可以通过 this.point.
属性.
访问图表数据
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)
}"))
我想在用 R 制作的 highcharter 图表上自定义弹出框(我相信称为工具提示)。
# 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")
当我将鼠标拖到图表条上时,它会提供一个弹出框,其中包含我指定的项目名称和贷款余额字段的信息。
是否可以为其他字段添加额外的文本 - 投资组合、贷款人、到期年 - 将鼠标悬停在系列上时显示?
您可以使用 hc_tooltip
并创建自定义 JS
格式化程序。
可以通过 this.point.
属性.
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)
}"))