Class: Axis

Highcharts. Axis

new Axis(chart, userOptions)

Create a new axis object. Called internally when instanciating a new chart or adding axes by Highcharts.Chart#addAxis.

A chart can have from 0 axes (pie chart) to multiples. In a normal, single series cartesian chart, there is one X axis and one Y axis.

The X axis or axes are referenced by Highcharts.Chart.xAxis, which is an array of Axis objects. If there is only one axis, it can be referenced through chart.xAxis[0], and multiple axes have increasing indices. The same pattern goes for Y axes.

If you need to get the axes from a series object, use the series.xAxis and series.yAxis properties. These are not arrays, as one series can only be associated to one X and one Y axis.

A third way to reference the axis programmatically is by id. Add an id in the axis configuration options, and get the axis by Highcharts.Chart#get.

Configuration options for the axes are given in options.xAxis and options.yAxis.

参数:
名字 类型 详情
chart Highcharts.Chart

The Chart instance to apply the axis on.

userOptions Highcharts.AxisOptions

Axis options.

成员

<readonly> categories :Array.<string>

If categories are present for the axis, names are used instead of numbers for that axis.

Since Highcharts 3.0, categories can also be extracted by giving each point a name and setting axis type to category. However, if you have multiple series, best practice remains defining the categories array.

Type:
  • Array.<string>
See also:

chart :Highcharts.Chart

The Chart that the axis belongs to.

Type:

coll :string

The collection where the axis belongs, for example xAxis, yAxis or colorAxis. Corresponds to properties on Chart, for example Highcharts.Chart.xAxis.

Type:
  • string

crosshair :boolean|Highcharts.AxisCrosshairOptions

The processed crosshair options.

Type:

horiz :boolean|undefined

Whether the axis is horizontal.

Type:
  • boolean | undefined

isXAxis :boolean|undefined

Whether the axis is the x-axis.

Type:
  • boolean | undefined

max :number|null

The maximum value of the axis. In a logarithmic axis, this is the logarithm of the real value, and the real value can be obtained from Highcharts.Axis#getExtremes.

Type:
  • number | null

min :number|null

The minimum value of the axis. In a logarithmic axis, this is the logarithm of the real value, and the real value can be obtained from Highcharts.Axis#getExtremes.

Type:
  • number | null

minorTicks :Highcharts.Dictionary.<Highcharts.Tick>

List of minor ticks mapped by position on the axis.

Type:
See also:

options :Highcharts.AxisOptions

Current options for the axis after merge of defaults and user's options.

Type:

reversed :boolean

Whether the axis is reversed. Based on the axis.reversed, option, but inverted charts have reversed xAxis by default.

Type:
  • boolean

series :Array.<Highcharts.Series>

All series associated to the axis.

Type:

side :number

The side on which the axis is rendered. 0 is top, 1 is right, 2 is bottom and 3 is left.

Type:
  • number

tickPositions :Highcharts.AxisTickPositionsArray|undefined

Contains the current positions that are laid out on the axis. The positions are numbers in terms of axis values. In a category axis they are integers, in a datetime axis they are also integers, but designating milliseconds.

This property is read only - for modifying the tick positions, use the tickPositioner callback or [axis.tickPositions( https://api.highcharts.com/highcharts/xAxis.tickPositions) option instead.

Type:

ticks :Highcharts.Dictionary.<Highcharts.Tick>

List of major ticks mapped by postition on axis.

Type:
See also:

userOptions :Highcharts.AxisOptions

User's options for this axis without defaults.

Type:

方法

addTitle( [display])

Adds the title defined in axis.options.title.

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

Whether or not to display the title.

applyGrouping()

Check the groupPixelWidth and apply the grouping if needed. Fired only after processing the data.

defaultLabelFormatter(this [, ctx])

The default label formatter. The context is a special config object for the label. In apps, use the labels.formatter instead, except when a modification is needed.

参数:
名字 类型 特质 详情
this Highcharts.AxisLabelsFormatterContextObject

Formatter context of axis label.

ctx Highcharts.AxisLabelsFormatterContextObject <可选>

Formatter context of axis label.

返回值:
string .

The formatted label content.

drawCrosshair( [e] [, point])

Internal function to draw a crosshair.

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

The event arguments from the modified pointer event, extended with chartX and chartY

point Highcharts.Point <可选>

The Point object if the crosshair snaps to points.

Fires:
  • Highcharts.Axis#event:afterDrawCrosshair
  • Highcharts.Axis#event:drawCrosshair

drilldownCategory(x [, originalEvent])

Drill down to a given category. This is the same as clicking on an axis label. If multiple series with drilldown are present, all will drill down to the given category.

See also Point.doDrilldown for drilling down on a single point instance.

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

The index of the category

originalEvent global.MouseEvent <可选>

The original event, used internally.

在线示例

getExtremes()

Get the current extremes for the axis.

返回值:
Highcharts.ExtremesObject .

An object containing extremes information.

在线示例

getLinearTickPositions(tickInterval, min, max)

Internal function to get the tick positions of a linear axis to round values like whole tens or every five.

参数:
名字 类型 详情
tickInterval number

The normalized tick interval.

min number

Axis minimum.

max number

Axis maximum.

返回值:
Array.<number> .

An array of axis values where ticks should be placed.

getLinePath(lineWidth)

Internal function to get the path for the axis line. Extended for polar charts.

参数:
名字 类型 详情
lineWidth number

The line width in pixels.

返回值:
Highcharts.SVGPathArray .

The SVG path definition in array form.

getMinorTickInterval()

Resolve the new minorTicks/minorTickInterval options into the legacy loosely typed minorTickInterval option.

返回值:

getMinorTickPositions()

Internal function to return the minor tick positions. For logarithmic axes, the same logic as for major ticks is reused.

返回值:
Array.<number> .

An array of axis values where ticks should be placed.

getPlotLinePath(options)

Create the path for a plot line that goes from the given value on this axis, across the plot to the opposite side. Also used internally for grid lines and crosshairs.

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

Options for the path.

返回值:
Highcharts.SVGPathArray | null .

The SVG path definition for the plot line.

getThreshold(threshold)

Get the zero plane either based on zero or on the min or max value. Used in bar and area plots.

参数:
名字 类型 详情
threshold number

The threshold in axis values.

返回值:
number | undefined .

The translated threshold position in terms of pixels, and corrected to stay within the axis bounds.

hasData()

Return true if the axis has associated data.

返回值:
boolean .

True if the axis has associated visible series and those series have either valid data points or explicit min and max settings.

hideCrosshair()

Hide the crosshair if visible.

init(chart, userOptions)

Overrideable function to initialize the axis.

参数:
名字 类型 详情
chart Highcharts.Chart

The Chart instance to apply the axis on.

userOptions AxisOptions

Axis options.

See also:
Fires:
  • Highcharts.Axis#event:afterInit
  • Highcharts.Axis#event:init

remove( [redraw])

Remove the axis from the chart.

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

Whether to redraw the chart following the remove.

在线示例

renderLine()

Render the axis line. Called internally when rendering and redrawing the axis.

renderMinorTick(pos, slideIn)

Render a minor tick into the given position. If a minor tick already exists in this position, move it.

参数:
名字 类型 详情
pos number

The position in axis values.

slideIn boolean

Whether the tick should animate in from last computed position

renderTick(pos, i, slideIn)

Render a major tick into the given position. If a tick already exists in this position, move it.

参数:
名字 类型 详情
pos number

The position in axis values.

i number

The tick index.

slideIn boolean

Whether the tick should animate in from last computed position

setCategories(categories [, redraw])

Set new axis categories and optionally redraw.

参数:
名字 类型 特质 默认值 详情
categories Array.<string>

The new categories.

redraw boolean <可选>
true

Whether to redraw the chart.

在线示例

setCompare( [compare] [, redraw])

Highcharts Stock only. Set the compare mode on all series belonging to an Y axis after render time.

参数:
名字 类型 特质 默认值 详情
compare string <可选>

The compare mode. Can be one of null (default), "value" or "percent".

redraw boolean <可选>
true

Whether to redraw the chart or to wait for a later call to Highcharts.Chart#redraw.

See also:
在线示例

setDataGrouping( [dataGrouping] [, redraw])

Highcharts Stock only. Force data grouping on all the axis' series.

参数:
名字 类型 特质 默认值 详情
dataGrouping boolean | Highcharts.DataGroupingOptionsObject <可选>

A dataGrouping configuration. Use false to disable data grouping dynamically.

redraw boolean <可选>
true

Whether to redraw the chart or wait for a later call to Highcharts.Chart#redraw.

setExtremes( [newMin] [, newMax] [, redraw] [, animation] [, eventArguments])

Set the minimum and maximum of the axes after render time. If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded off to the nearest tick. To prevent this, these options can be set to false before calling setExtremes. Also, setExtremes will not allow a range lower than the minRange option, which by default is the range of five points.

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

The new minimum value.

newMax number <可选>

The new maximum value.

redraw boolean <可选>
true

Whether to redraw the chart or wait for an explicit call to Highcharts.Chart#redraw

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

Enable or modify animations.

eventArguments * <可选>

Arguments to be accessed in event handler.

Fires:
  • Highcharts.Axis#event:setExtremes
在线示例

setTitle(titleOptions [, redraw])

Update the axis title by options after render time.

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

The additional title options.

redraw boolean <可选>
true

Whether to redraw the chart after setting the title.

在线示例

toPixels(value, paneCoordinates)

Translate a value in terms of axis units into pixels within the chart.

参数:
名字 类型 详情
value number

A value in terms of axis units.

paneCoordinates boolean

Whether to return the pixel coordinate relative to the chart or just the axis/pane itself.

返回值:
number .

Pixel position of the value on the chart or axis.

toValue(pixel [, paneCoordinates])

Translate a pixel position along the axis to a value in terms of axis units.

参数:
名字 类型 特质 默认值 详情
pixel number

The pixel value coordinate.

paneCoordinates boolean <可选>
false

Whether the input pixel is relative to the chart or just the axis/pane itself.

返回值:
number .

The axis value.

update(options [, redraw])

Update an axis object with a new set of options. The options are merged with the existing options, so only new or altered options need to be specified.

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

The new options that will be merged in with existing options on the axis.

redraw boolean <可选>
true

Whether to redraw the chart after the axis is altered. If doing more operations on the chart, it is a good idea to set redraw to false and call Highcharts.Chart#redraw after.

在线示例