Hi,
Welcome to our forum and thanks for contacting us with your question!
Combining fetching with drilldown is perfectly possible in Higcharts. You can take advantage of the
point.event.click listener, and fetch the data for drill down when needed.
The basic structure would be similar to this mock code:
Code: Select all
Highcharts.getJSON('data/initialData.json', function (data) {
Highcharts.mapChart('container', {
series: [{
type: 'treemap',
data: data,
point: {
events: {
click: function () {
// Fetch the children data from the server
fetchChildrenData(this.name);
}
}
}
}],
drilldown: {
series: [] // Initially empty, will be filled on fetch
}
});
});
function fetchChildrenData(parentName) {
// Example AJAX request to fetch children data based on parent name
fetch(`data/childrenData.json?parent=${parentName}`)
.then(response => response.json())
.then(childrenData => {
// Update the chart with the new data
const drilldownSeries = {
id: `${parentName}`,
data: childrenData
};
const chart = Highcharts.charts[0]; // Assuming there's only one chart
chart.addSeriesAsDrilldown(chart.series[0].points.find(point => point.name === parentName), drilldownSeries)
})
.catch(error => console.error('Error fetching children data:', error));
}
I also prepared for you a sample demo mocking drilldown and fetch, I hope you will find it useful:
https://jsfiddle.net/BlackLabel/cgexonsy/
If you have further inquiries, you may reach out to me at any time.
Best regards,