Highcharts Drilldown Column Chart
A drilldown column chart (Drilldown Column Chart) allows users to click a column in the chart to see more detailed information about that data.
For example, in a browser market share chart, the overall share of browsers such as Chrome, Firefox, and Safari is shown first; after clicking a browser, the market share of different versions is displayed.
Highcharts through drilldown configuration implements this feature, supporting switching between different data levels.
Configure
drilldown: Drilldown
drilldown Used to configure the drilldown feature of the chart.
The most basic configuration is as follows:
drilldown: {
series: drilldownSeries
}
WheredrilldownSeries is an array containing the drilldown data series.
To use this feature, you need to include the Highcharts main library and the Drilldown module:
Linking Parent Data and Drilldown Data
A drilldown chart is mainly linked through the drilldown property in the parent data point and the id in the drilldown data series.
For example:
series: [{
name: '浏览器',
data: [{
name: 'Chrome',
y: 40,
drilldown: 'chrome'
}]
}],
drilldown: {
series: [{
id: 'chrome',
name: 'Chrome 版本',
data: [
['Chrome 18', 25],
['Chrome 19', 15]
]
}]
}
In the configuration above:
nameindicates the name of a data point or data series.yindicates the value of a data point.drilldown: 'chrome'specifies the drilldown series to display after clicking.id: 'chrome'is used to link the corresponding parent data point.datacontains the detailed data shown after drilling down.
After clicking the Chrome column, Highcharts switches to id is chrome drilldown series.
If a data point has no drilldown data, you can omit drilldown, or set it to null。
Example
Below we demonstrate how to create a drilldown column chart using browser market share data.
The chart first aggregates data by browser brand; after clicking the corresponding column, it shows the market share of different browser versions.
This example continues to use the historical browser version data from the original tutorial. The data is only for demonstrating Highcharts' drilldown feature and is not current browser market share.
**Filename:**highcharts_column_drilldown.htm
Example
content="width=device-width, initial-scale=1.0">
Highcharts Drilldown Column Chart - Runoob Tutorial
**Note:** This example no longer depends on jQuery, but directly uses Highcharts.chart() to create the chart. The data is parsed by JavaScript and automatically aggregated by browser brand.
Some records in the sample data include third-party customized versions, such as Maxthon Edition and Tencent Traveler Edition. They are classified according to the browser family marked in the original data, and the version names are retained to demonstrate detailed drilldown.
Since the original data only contains some historical browser versions, all column values should be understood as the aggregated share of these sample records, not a recalculation of complete market statistics.
The original online demo is below:
**Note:** The "Try it" and iframe above retain the original demo file address. If you need them to run this revised version, you also need to sync the new HTML to the corresponding highcharts_column_drilldown.htm demo file.
Code Explanation
1. Set the Column Chart Type
Pass chart.type Specify the chart type as column:
chart: {
type: 'column'
}
If you need to change the column chart to a bar chart, you can change column to bar。
2. Configure the Main Data Series
The main data series uses series Definition:
series: [{
name: '浏览器品牌',
colorByPoint: true,
data: brandsData
}]
Where:
name: the data series name.colorByPoint: assign different colors to different data points.data: the main data to display.
Each data point that supports drilldown needs to set the drilldown property to link it to the drilldown data series.
3. Configure the Drilldown Data
Drilldown data passes through drilldown.series Definition:
drilldown: {
series: [{
id: 'Chrome',
name: 'Chrome 版本',
data: [
['18.0', 8.01],
['19.0', 7.73],
['17.0', 1.13]
]
}]
}
When the user clicks the parent data point corresponding to Chrome , the chart displays the corresponding version data.
**Note:** The three data items above are only part of the records extracted from the full example, used to illustrate the configuration format.
4. Configure Drilldown Navigation
Highcharts supports using breadcrumb navigation to return to the previous level of data.
can be used via drilldown.breadcrumbs Adjust the navigation position:
drilldown: {
breadcrumbs: {
position: {
align: 'right'
}
},
series: drilldownSeries
}
After drilling down, users can click the navigation to return to the parent chart.
5. Configure the Tooltip
Pass tooltip You can set the content displayed on hover.
tooltip: {
headerFormat: '',
pointFormat:
'{point.name}
' +
'市场份额:{point.y:.2f}%'
}
Where{point.name} indicates the current data point name,{point.y:.2f} indicates the value rounded to two decimal places.
Common questions
1. Clicking a column does not go to the next level?
First check whether modules/drilldown.js module.
is loaded, then check the drilldown value in the parent data point to see whether it exactly matches the drilldown.series of a series in id .
2. Can multi-level drilldown be implemented?
Yes. Highcharts supports multi-level drilldown.
Just continue to set the drilldownin the next-level data points, and provide a matching id。
3. Must drilldown data be loaded in advance?
Not necessarily.
For charts with a small amount of data, you can provide all detailed data at initialization via drilldown.series .
If the data volume is large, you can also listen to the drilldown event, dynamically request the server based on the clicked data point, and then use chart.addSeriesAsDrilldown() to load the details.Refer to the official API。
4. What is the difference between a drilldown column chart and a stacked column chart?
A drilldown column chart focuses on switching between data at different levels; a stacked column chart focuses on showing the composition of multiple series within the same column.
To implement a stacked column chart, use configurations such as plotOptions.column.stacking instead of just adding drilldown。
Highcharts Column Chart