const chart = Highcharts.chart('container', {
chart: {
zooming: { type: 'x' },
events: {
load: function() {
console.log('Chart loaded with', this.series.length, 'series');
},
selection: function(event) {
if (!event.resetSelection) {
const min = event.xAxis[0].min;
const max = event.xAxis[0].max;
console.log('Zoomed to:', min, max);
// Load additional data
fetch(`/api/data?min=${min}&max=${max}`)
.then(res => res.json())
.then(data => {
this.series[0].setData(data);
});
}
},
click: function(event) {
const x = event.xAxis[0].value;
const y = event.yAxis[0].value;
this.series[0].addPoint([x, y]);
}
}
},
xAxis: {
events: {
afterSetExtremes: function(e) {
console.log('X-axis range:', e.min, e.max);
if (e.trigger === 'navigator') {
console.log('Changed via navigator');
}
}
}
},
plotOptions: {
series: {
allowPointSelect: true,
cursor: 'pointer',
events: {
click: function(event) {
console.log('Series:', this.name);
console.log('Point:', event.point.y);
},
hide: function() {
console.log('Hidden:', this.name);
},
show: function() {
console.log('Shown:', this.name);
},
legendItemClick: function() {
return confirm('Toggle ' + this.name + '?');
},
afterAnimate: function() {
console.log('Animation done:', this.name);
}
},
point: {
events: {
click: function() {
alert('Value: ' + this.y);
},
mouseOver: function() {
this.series.chart.setTitle({
text: this.category + ': ' + this.y
});
},
select: function() {
console.log('Selected point:', this.y);
}
}
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0]
}]
});
// Add custom event handler
Highcharts.addEvent(chart, 'render', function() {
console.log('Custom render handler');
});