The Chart.get()
method can be used to get an axis, series, or a point by its ID. It returns an object of an axis, series, or a point containing various properties. This method is useful due to faster access to the mentioned components, as we don't have to manually navigate through the object hierarchy of a chart.
Consider the following example from Chapter 7, Theming with Highcharts, modified to include an ID for the Windows 7 data point:
$( '#chart_container' ).highcharts({ chart: { type: 'pie' }, title: { ... }, tooltip: { ... },aotOptions: { ... }, series: [{ name: 'Windows versions', data: [ { name: 'Win 7', id: 'win7', y: 55.03 }, ... ] }] }
While being on the top-level chart
object, we can call the get()
method in the callback function to get the object of the win7
data point:
var win7Point = this.get( 'win7' );
Upon logging the win7Point
variable in the console, we get the following object:
The win7Point
object also contains the series
property, which can be used to navigate upwards in the object hierarchy.
While being tremendously useful, the limitation of the Chart.get()
method is that it can only be used to retrieve axes, series, or points that have already been assigned an ID.