% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme.R
\name{hd_add_js}
\alias{hd_add_js}
\title{Inject JavaScript into a Highcharts Widget}
\usage{
hd_add_js(
  hc,
  code = NULL,
  file = NULL,
  plugin = NULL,
  where = c("load", "render")
)
}
\arguments{
\item{hc}{A \code{highchart} object.}

\item{code}{Character or \code{NULL}. Raw JavaScript string.}

\item{file}{Character or \code{NULL}. Path to a \code{.js} file to read and inject.}

\item{plugin}{Character or \code{NULL}. Name of a plugin bundled in \verb{inst/js/}.}

\item{where}{\code{"load"} (default) or \code{"render"}.}
}
\value{
The \code{highchart} object with JS injected.
}
\description{
Appends custom JavaScript to a \code{highchart} object via
\verb{chart.events.<where>}.  Use this for hand-written callbacks and plugins.
For Highcharts built-in modules (accessibility, exporting, etc.) use
\code{\link[highcharter:hc_add_dependency]{highcharter::hc_add_dependency()}} instead.
}
\details{
Exactly one of \code{code}, \code{file}, or \code{plugin} must be supplied.
}
\examples{
if (interactive()) {
spec <- hd_spec(mtcars, "wt", "mpg")
fig  <- hd_make(spec, "scatter")
fig  <- hd_add_js(fig, code = "console.log('chart loaded');")
}

}
