Class: Chart

Highcharts. Chart

new Chart( [renderTo], options [, callback])

The Chart class. The recommended constructor is Highcharts#chart.

参数:
名字 类型 特质 详情
renderTo string | Highcharts.HTMLDOMElement <可选>

The DOM element to render to, or its id.

options Highcharts.Options

The chart options structure.

callback Highcharts.ChartCallbackFunction <可选>

Function to run when the chart has loaded and and all external images are loaded. Defining a chart.events.load handler is equivalent.

Example
let chart = Highcharts.chart('container', {
       title: {
              text: 'My chart'
       },
       series: [{
           data: [1, 3, 2, 4]
       }]
})

成员

axes :Array.<Highcharts.Axis>

All the axes in the chart.

Type:
See also:
  • Highcharts.Chart.xAxis
  • Highcharts.Chart.yAxis

chartHeight :number

The current pixel height of the chart.

Type:
  • number

chartWidth :number

The current pixel width of the chart.

Type:
  • number

container :Highcharts.HTMLDOMElement

The containing HTML element of the chart. The container is dynamically inserted into the element given as the renderTo parameter in the Highcharts#chart constructor.

Type:

credits :Highcharts.SVGElement

The chart's credits label. The label has an update method that allows setting new options as per the credits options set.

Type:

data :Highcharts.Data|undefined

The data parser for this chart.

Type:

hoverPoint :Highcharts.Point|null

Contains the original hovered point.

Type:

hoverPoints :Array.<Highcharts.Point>|null

Contains all hovered points.

Type:

hoverSeries :Highcharts.Series|null

Contains the original hovered series.

Type:

<readonly> index :number

Index position of the chart in the Highcharts#charts property.

Type:
  • number

inverted :boolean|undefined

The flag is set to true if a series of the chart is inverted.

Type:
  • boolean | undefined

legend :Highcharts.Legend

The overview of the chart's series.

Type:

numberFormatter :Highcharts.NumberFormatterCallbackFunction

Callback function to override the default function that formats all the numbers in the chart. Returns a string with the formatted number.

Type:

options :Highcharts.Options

The options structure for the chart after merging #defaultOptions and #userOptions. It contains members for the sub elements like series, legend, tooltip etc.

Type:
  • Highcharts.Options

plotHeight :number

The current height of the plot area in pixels.

Type:
  • number

plotLeft :number

The current left position of the plot area in pixels.

Type:
  • number

plotTop :number

The current top position of the plot area in pixels.

Type:
  • number

plotWidth :number

The current width of the plot area in pixels.

Type:
  • number

pointer :Highcharts.Pointer

The Pointer that keeps track of mouse and touch interaction.

Type:

renderer :Highcharts.SVGRenderer

The renderer instance of the chart. Each chart instance has only one associated renderer.

Type:

series :Array.<Highcharts.Series>

All the current series in the chart.

Type:

styledMode :boolean

Whether the chart is in styled mode, meaning all presentatinoal attributes are avoided.

Type:
  • boolean

subtitle :Highcharts.SubtitleObject

The chart subtitle. The subtitle has an update method that allows modifying the options directly or indirectly via chart.update.

Type:

time :Highcharts.Time

The Time object associated with the chart. Since v6.0.5, time settings can be applied individually for each chart. If no individual settings apply, the Time object is shared by all instances.

Type:

title :Highcharts.TitleObject

The chart title. The title has an update method that allows modifying the options directly or indirectly via chart.update.

Type:
在线示例

tooltip :Highcharts.Tooltip

Tooltip object for points of series.

Type:

userOptions :Highcharts.Options

The original options given to the constructor or a chart factory like Highcharts.chart and Highcharts.stockChart.

Type:
  • Highcharts.Options

xAxis :Array.<Highcharts.Axis>

A collection of the X axes in the chart.

Type:

yAxis :Array.<Highcharts.Axis>

A collection of the Y axes in the chart.

Type:
To Do:
  • Make events official: Fire the event `afterInit`.

方法

addAnnotation(options [, redraw])

Add an annotation to the chart after render time.

参数:
名字 类型 特质 详情
options Highcharts.AnnotationsOptions

The annotation options for the new, detailed annotation.

redraw boolean <可选>
返回值:
Highcharts.Annotation .
  • The newly generated annotation.

addAxis(options [, isX] [, redraw] [, animation])

Add an axis to the chart after render time. Note that this method should never be used when adding data synchronously at chart render time, as it adds expense to the calculations and rendering. When adding data at the same time as the chart is initialized, add the axis as a configuration option instead.

参数:
名字 类型 特质 默认值 详情
options Highcharts.AxisOptions

The axis options.

isX boolean <可选>
false

Whether it is an X axis or a value axis.

redraw boolean <可选>
true

Whether to redraw the chart after adding.

animation boolean | Partial.<Highcharts.AnimationOptionsObject> <可选>
true

Whether and how to apply animation in the redraw.

返回值:
Highcharts.Axis .

The newly generated Axis object.

在线示例

addColorAxis(options [, redraw] [, animation])

Add a color axis to the chart after render time. Note that this method should never be used when adding data synchronously at chart render time, as it adds expense to the calculations and rendering. When adding data at the same time as the chart is initialized, add the axis as a configuration option instead.

参数:
名字 类型 特质 默认值 详情
options Highcharts.ColorAxisOptions

The axis options.

redraw boolean <可选>
true

Whether to redraw the chart after adding.

animation boolean | Partial.<Highcharts.AnimationOptionsObject> <可选>
true

Whether and how to apply animation in the redraw.

返回值:
Highcharts.ColorAxis .

The newly generated Axis object.

在线示例

addCredits( [credits])

Set a new credits label for the chart.

参数:
名字 类型 特质 详情
credits Highcharts.CreditsOptions <可选>

A configuration object for the new credits.

在线示例

addSeries(options [, redraw] [, animation])

Add a series to the chart after render time. Note that this method should never be used when adding data synchronously at chart render time, as it adds expense to the calculations and rendering. When adding data at the same time as the chart is initialized, add the series as a configuration option instead. With multiple axes, the offset is dynamically adjusted.

参数:
名字 类型 特质 默认值 详情
options Highcharts.SeriesOptionsType

The config options for the series.

redraw boolean <可选>
true

Whether to redraw the chart after adding.

animation boolean | Partial.<Highcharts.AnimationOptionsObject> <可选>

Whether to apply animation, and optionally animation configuration.

Fires:
  • Highcharts.Chart#event:addSeries
  • Highcharts.Chart#event:afterAddSeries
返回值:
Highcharts.Series .

The newly created series object.

在线示例

addSeriesAsDrilldown(point, options)

Add a series to the chart as drilldown from a specific point in the parent series. This method is used for async drilldown, when clicking a point in a series should result in loading and displaying a more high-resolution series. When not async, the setup is simpler using the drilldown.series options structure.

参数:
名字 类型 详情
point Highcharts.Point

The point from which the drilldown will start.

options Highcharts.SeriesOptionsType

The series options for the new, detailed series.

在线示例

cancelSonify( [fadeOut])

Cancel current sonification and reset cursor.

参数:
名字 类型 特质 默认值 详情
fadeOut boolean <可选>
true

Fade out as we pause to avoid clicks.

依赖:
  • module:modules/sonification
返回值:

destroy()

Remove the chart and purge memory. This method is called internally before adding a second chart into the same container, as well as on window unload to prevent leaks.

Fires:
  • Highcharts.Chart#event:destroy
在线示例

downloadCSV()

Generates a data URL of CSV for local download in the browser. This is the default action for a click on the 'Download CSV' button.

See Highcharts.Chart#getCSV to get the CSV data itself.

依赖:
  • module:modules/exporting

downloadXLS()

Generates a data URL of an XLS document for local download in the browser. This is the default action for a click on the 'Download XLS' button.

See Highcharts.Chart#getTable to get the table data itself.

依赖:
  • module:modules/exporting

drillUp()

When the chart is drilled down to a child series, calling chart.drillUp() will drill up to the parent series.

依赖:
  • module:modules/drilldown
在线示例

exportChart(exportingOptions, chartOptions)

Exporting module required. Submit an SVG version of the chart to a server along with some parameters for conversion.

参数:
名字 类型 详情
exportingOptions Highcharts.ExportingOptions

Exporting options in addition to those defined in exporting.

chartOptions Highcharts.Options

Additional chart options for the exported chart. For example a different background color can be added here, or dataLabels for export only.

依赖:
  • module:modules/exporting
在线示例

exportChartLocal( [exportingOptions] [, chartOptions])

Exporting and offline-exporting modules required. Export a chart to an image locally in the user's browser.

参数:
名字 类型 特质 详情
exportingOptions Highcharts.ExportingOptions <可选>

Exporting options, the same as in Highcharts.Chart#exportChart.

chartOptions Highcharts.Options <可选>

Additional chart options for the exported chart. For example a different background color can be added here, or dataLabels for export only.

依赖:
  • module:modules/exporting
返回值:

fromLatLonToPoint(latLon)

Highmaps only. Get chart coordinates from latitude/longitude. Returns an object with x and y values corresponding to the xAxis and yAxis.

参数:
名字 类型 详情
latLon Highcharts.MapLatLonObject

Coordinates.

依赖:
  • module:modules/map
返回值:
Highcharts.MapCoordinateObject .

X and Y coordinates in terms of chart axis values.

在线示例

fromPointToLatLon(point)

Highmaps only. Calculate latitude/longitude values for a point. Returns an object with the numeric properties lat and lon.

参数:
名字 类型 详情
point Highcharts.Point | Highcharts.MapCoordinateObject

A Point instance or anything containing x and y properties with numeric values.

依赖:
  • module:modules/map
返回值:
Highcharts.MapLatLonObject | undefined .

An object with lat and lon properties.

在线示例

get(id)

Get an axis, series or point object by id as given in the configuration options. Returns undefined if no item is found.

参数:
名字 类型 详情
id string

The id as given in the configuration options.

返回值:
Highcharts.Axis | Highcharts.Series | Highcharts.Point | undefined .

The retrieved item.

在线示例

getChartHTML()

Return the unfiltered innerHTML of the chart container. Used as hook for plugins. In styled mode, it also takes care of inlining CSS style rules.

See also:
依赖:
  • module:modules/exporting
返回值:
string .

The unfiltered SVG of the chart.

getCSV( [useLocalDecimalPoint])

Export-data module required. Returns the current chart data as a CSV string.

参数:
名字 类型 特质 详情
useLocalDecimalPoint boolean <可选>

Whether to use the local decimal point as detected from the browser. This makes it easier to export data to Excel in the same locale as the user is.

返回值:
string .

CSV representation of the data

getCurrentSonifyPoints()

Get a list of the points currently under cursor.

依赖:
  • module:modules/sonification
返回值:
Array.<Highcharts.Point> .

The points currently under the cursor.

getDataRows( [multiLevelHeaders])

Export-data module required. Returns a two-dimensional array containing the current chart data.

参数:
名字 类型 特质 详情
multiLevelHeaders boolean <可选>

Use multilevel headers for the rows by default. Adds an extra row with top level headers. If a custom columnHeaderFormatter is defined, this can override the behavior.

Fires:
  • Highcharts.Chart#event:exportData
返回值:
Array.<Array.<(number|string)>> .

The current chart data

getFilename()

Get the default file name used for exported charts. By default it creates a file name based on the chart title.

依赖:
  • module:modules/exporting
返回值:
string .

A file name without extension.

getSelectedPoints()

Returns an array of all currently selected points in the chart. Points can be selected by clicking or programmatically by the Highcharts.Point#select function.

返回值:
Array.<Highcharts.Point> .

The currently selected points.

在线示例

getSelectedSeries()

Returns an array of all currently selected series in the chart. Series can be selected either programmatically by the Highcharts.Series#select function or by checking the checkbox next to the legend item if series.showCheckBox is true.

返回值:
Array.<Highcharts.Series> .

The currently selected series.

在线示例

getSVG( [chartOptions])

Return an SVG representation of the chart.

参数:
名字 类型 特质 详情
chartOptions Highcharts.Options <可选>

Additional chart options for the generated SVG representation. For collections like xAxis, yAxis or series, the additional options is either merged in to the original item of the same id, or to the first item if a common id is not found.

依赖:
  • module:modules/exporting
Fires:
  • Highcharts.Chart#event:getSVG
返回值:
string .

The SVG representation of the rendered chart.

在线示例

getTable( [useLocalDecimalPoint])

Export-data module required. Build a HTML table with the chart's current data.

参数:
名字 类型 特质 详情
useLocalDecimalPoint boolean <可选>

Whether to use the local decimal point as detected from the browser. This makes it easier to export data to Excel in the same locale as the user is.

Fires:
  • Highcharts.Chart#event:afterGetTable
返回值:
string .

HTML representation of the data.

在线示例

hideData()

Export-data module required. Hide the data table when visible.

init(userOptions [, callback])

Overridable function that initializes the chart. The constructor's arguments are passed on directly.

参数:
名字 类型 特质 详情
userOptions Highcharts.Options

Custom options.

callback function <可选>

Function to run when the chart has loaded and and all external images are loaded.

Fires:
  • Highcharts.Chart#event:init
  • Highcharts.Chart#event:afterInit
返回值:

isInsidePlot(plotX, plotY [, options])

Check whether a given point is within the plot area.

参数:
名字 类型 特质 详情
plotX number

Pixel x relative to the plot area.

plotY number

Pixel y relative to the plot area.

options Highcharts.ChartIsInsideOptionsObject <可选>

Options object.

返回值:
boolean .

Returns true if the given point is inside the plot area.

langFormat(langKey, context)

Apply context to a format string from lang options of the chart.

参数:
名字 类型 详情
langKey string

Key (using dot notation) into lang option structure.

context Highcharts.Dictionary.<*>

Context to apply to the format string.

依赖:
  • module:modules/accessibility
返回值:
string .

The formatted string.

mapZoom( [howMuch] [, centerX] [, centerY] [, mouseX] [, mouseY])

Highmaps only. Zoom in or out of the map. See also Highcharts.Point#zoomTo. See Highcharts.Chart#fromLatLonToPoint for how to get the centerX and centerY parameters for a geographic location.

参数:
名字 类型 特质 详情
howMuch number <可选>

How much to zoom the map. Values less than 1 zooms in. 0.5 zooms in to half the current view. 2 zooms to twice the current view. If omitted, the zoom is reset.

centerX number <可选>

The X axis position to center around if available space.

centerY number <可选>

The Y axis position to center around if available space.

mouseX number <可选>

Fix the zoom to this position if possible. This is used for example in mousewheel events, where the area under the mouse should be fixed as we zoom in.

mouseY number <可选>

Fix the zoom to this position if possible.

返回值:

pauseSonify( [fadeOut])

Pause the running sonification.

参数:
名字 类型 特质 默认值 详情
fadeOut boolean <可选>
true

Fade out as we pause to avoid clicks.

依赖:
  • module:modules/sonification
返回值:

print()

Exporting module required. Clears away other elements in the page and prints the chart as it is displayed. By default, when the exporting module is enabled, a context button with a drop down menu in the upper right corner accesses this function.

依赖:
  • module:modules/exporting
Fires:
  • Highcharts.Chart#event:beforePrint
  • Highcharts.Chart#event:afterPrint
返回值:
在线示例

redraw( [animation])

Redraw the chart after changes have been done to the data, axis extremes chart size or chart elements. All methods for updating axes, series or points have a parameter for redrawing the chart. This is true by default. But in many cases you want to do more than one operation on the chart before redrawing, for example add a number of points. In those cases it is a waste of resources to redraw the chart for each new point added. So you add the points and call chart.redraw() after.

参数:
名字 类型 特质 详情
animation boolean | Partial.<Highcharts.AnimationOptionsObject> <可选>

If or how to apply animation to the redraw.

Fires:
  • Highcharts.Chart#event:afterSetExtremes
  • Highcharts.Chart#event:beforeRedraw
  • Highcharts.Chart#event:predraw
  • Highcharts.Chart#event:redraw
  • Highcharts.Chart#event:render
  • Highcharts.Chart#event:updatedData

reflow( [e])

Reflows the chart to its container. By default, the chart reflows automatically to its container following a window.resize event, as per the chart.reflow option. However, there are no reliable events for div resize, so if the container is resized without a window resize event, this must be called explicitly.

参数:
名字 类型 特质 详情
e global.Event <可选>

Event arguments. Used primarily when the function is called internally as a response to window resize.

在线示例

removeAnnotation(idOrAnnotation)

Remove an annotation from the chart.

参数:
名字 类型 详情
idOrAnnotation number | string | Highcharts.Annotation

The annotation's id or direct annotation object.

resetSonifyCursor()

Reset cursor to start. Requires series.sonify or chart.sonify to have been played at some point earlier.

依赖:
  • module:modules/sonification
返回值:

resetSonifyCursorEnd()

Reset cursor to end. Requires series.sonify or chart.sonify to have been played at some point earlier.

依赖:
  • module:modules/sonification
返回值:

resumeSonify(onEnd)

Resume the currently running sonification. Requires series.sonify or chart.sonify to have been played at some point earlier.

参数:
名字 类型 详情
onEnd function

Callback to call when play finished.

依赖:
  • module:modules/sonification
返回值:

rewindSonify(onEnd)

Play backwards from cursor. Requires series.sonify or chart.sonify to have been played at some point earlier.

参数:
名字 类型 详情
onEnd function

Callback to call when play finished.

依赖:
  • module:modules/sonification
返回值:

setCaption(options)

Set the caption options. This can also be done from Highcharts.Chart#update.

参数:
名字 类型 详情
options Highcharts.CaptionOptions

New caption options. The caption text itself is set by the options.text property.

setClassName( [className])

Set the chart container's class name, in addition to highcharts-container.

参数:
名字 类型 特质 详情
className string <可选>

The additional class name.

setSize( [width] [, height] [, animation])

Resize the chart to a given width and height. In order to set the width only, the height argument may be skipped. To set the height only, pass undefined for the width.

参数:
名字 类型 特质 默认值 详情
width number | null <可选>

The new pixel width of the chart. Since v4.2.6, the argument can be undefined in order to preserve the current value (when setting height only), or null to adapt to the width of the containing element.

height number | null <可选>

The new pixel height of the chart. Since v4.2.6, the argument can be undefined in order to preserve the current value, or null in order to adapt to the height of the containing element.

animation boolean | Partial.<Highcharts.AnimationOptionsObject> <可选>
true

Whether and how to apply animation.

Fires:
  • Highcharts.Chart#event:endResize
  • Highcharts.Chart#event:resize
返回值:
在线示例

setSonifyCursor(points)

Set the cursor to a point or set of points in different series.

参数:
名字 类型 详情
points Highcharts.Point | Array.<Highcharts.Point>

The point or points to set the cursor to. If setting multiple points under the cursor, the points have to be in different series that are being played simultaneously.

依赖:
  • module:modules/sonification

setSubtitle(options)

Shortcut to set the subtitle options. This can also be done from Highcharts.Chart#update or Highcharts.Chart#setTitle.

参数:
名字 类型 详情
options Highcharts.SubtitleOptions

New subtitle options. The subtitle text itself is set by the options.text property.

setTitle( [titleOptions] [, subtitleOptions] [, redraw])

Set a new title or subtitle for the chart.

参数:
名字 类型 特质 详情
titleOptions Highcharts.TitleOptions <可选>

New title options. The title text itself is set by the titleOptions.text property.

subtitleOptions Highcharts.SubtitleOptions <可选>

New subtitle options. The subtitle text itself is set by the subtitleOptions.text property.

redraw boolean <可选>

Whether to redraw the chart or wait for a later call to chart.redraw().

在线示例

showLoading( [str])

Dim the chart and show a loading text or symbol. Options for the loading screen are defined in the loading options.

参数:
名字 类型 特质 详情
str string <可选>

An optional text to show in the loading label instead of the default one. The default text is set in lang.loading.

在线示例

showResetZoom()

Display the zoom button, so users can reset zoom to the default view settings.

Fires:
  • Highcharts.Chart#event:afterShowResetZoom
  • Highcharts.Chart#event:beforeShowResetZoom

sonify( [options])

Sonify a chart.

参数:
名字 类型 特质 详情
options Highcharts.SonificationOptions <可选>

The options for sonifying this chart. If not provided, uses options set on chart and series.

依赖:
  • module:modules/sonification
在线示例

transformFromLatLon(latLon, transform)

Highmaps only. Get point from latitude and longitude using specified transform definition.

参数:
名字 类型 详情
latLon Highcharts.MapLatLonObject

A latitude/longitude object.

transform *

The transform definition to use as explained in the documentation.

依赖:
  • module:modules/map
返回值:
Highcharts.MapCoordinateObject .

An object with x and y properties.

在线示例

transformToLatLon(point, transform)

Highmaps only. Get latLon from point using specified transform definition. The method returns an object with the numeric properties lat and lon.

参数:
名字 类型 详情
point Highcharts.Point | Highcharts.MapCoordinateObject

A Point instance, or any object containing the properties x and y with numeric values.

transform *

The transform definition to use as explained in the documentation.

依赖:
  • module:modules/map
返回值:
Highcharts.MapLatLonObject | undefined .

An object with lat and lon properties.

在线示例

update(options [, redraw] [, oneToOne] [, animation])

A generic function to update any element of the chart. Elements can be enabled and disabled, moved, re-styled, re-formatted etc.

A special case is configuration objects that take arrays, for example xAxis, yAxis or series. For these collections, an id option is used to map the new option set to an existing object. If an existing object of the same id is not found, the corresponding item is updated. So for example, running chart.update with a series item without an id, will cause the existing chart's series with the same index in the series array to be updated. When the oneToOne parameter is true, chart.update will also take care of adding and removing items from the collection. Read more under the parameter description below.

Note that when changing series data, chart.update may mutate the passed data options.

See also the responsive option set. Switching between responsive.rules basically runs chart.update under the hood.

参数:
名字 类型 特质 默认值 详情
options Highcharts.Options

A configuration object for the new chart options.

redraw boolean <可选>
true

Whether to redraw the chart.

oneToOne boolean <可选>
false

When true, the series, xAxis, yAxis and annotations collections will be updated one to one, and items will be either added or removed to match the new updated options. For example, if the chart has two series and we call chart.update with a configuration containing three series, one will be added. If we call chart.update with one series, one will be removed. Setting an empty series array will remove all series, but leaving out theseries property will leave all series untouched. If the series have id's, the new series options will be matched by id, and the remaining ones removed.

animation boolean | Partial.<Highcharts.AnimationOptionsObject> <可选>
true

Whether to apply animation, and optionally animation configuration.

Fires:
  • Highcharts.Chart#event:update
  • Highcharts.Chart#event:afterUpdate
在线示例

viewData()

Export-data module required. View the data in a table below the chart.

Fires:
  • Highcharts.Chart#event:afterViewData

zoomOut()

Zoom the chart out after a user has zoomed in. See also Axis.setExtremes.

Fires:
  • Highcharts.Chart#event:selection