Core conceptsAPI MethodsEventBus· 5 min read
Events API & Programmatic Methods
EventBus subscriptions, lifecycle hooks, viewport manipulation methods, and headless imperative controls.
Every QuaCharts instance exposes a strongly-typed EventBus and an imperative API surface for zooming, panning, series mutation, and state queries without tearing down the chart.
Core Event Subscriptions
| Event Name | Payload Arguments | Trigger Condition |
|---|---|---|
| pointClick | { point, series, event } | User clicked or tapped directly on a data point |
| pointHover | { point, series, event } | Cursor entered magnetic snapping zone of a data point |
| zoom | { minX, maxX, minY, maxY } | User zoomed via wheel, box selection, or programmatic call |
| pan | { fromX, toX, deltaX } | User dragged or scrubbed the chart viewport horizontally |
| redraw | { timestamp, durationMs } | Fired immediately after an animation frame render completes |
| seriesVisibleChange | { seriesId, visible } | Legend item toggled or series programmatically shown/hidden |
| export | { format, dataUrl } | Triggered when PNG/SVG export generation completes |
Subscribing to Events
events-demo.ts
1
const chart = createLineChart('#chart', options);
2
3
// Listen to point clicks
4
const unsubscribeClick = chart.events.on('pointClick', ({ point, series }) => {
5
console.log(`Clicked series ${series.name} at X: ${point.x}, Y: ${point.y}`);
6
});
7
8
// Listen to viewport zoom to synchronize external tables or order books
9
chart.events.on('zoom', ({ minX, maxX }) => {
10
fetchHistoricalTradesInWindow(minX, maxX);
11
});
12
13
// Clean up listener later if needed
14
// unsubscribeClick();
Imperative Programmatic Methods
Control the chart camera and dataset dynamically from your application buttons or external keyboards:
imperative-controls.ts
1
// Zoom into a specific time window [fromMillis, toMillis]
2
chart.zoomTo(Date.UTC(2026, 9, 1), Date.UTC(2026, 9, 15));
3
4
// Pan viewport by a relative delta (+100px or -100px)
5
chart.panBy(120);
6
7
// Reset zoom to fit full dataset extent
8
chart.resetZoom();
9
10
// Add or remove series at runtime
11
chart.addSeries({
12
id: 'benchmark-sp500',
13
name: 'S&P 500',
14
type: 'line',
15
data: sp500Data,
16
});
17
18
chart.removeSeries('old-series-id');
19
20
// Export canvas image directly to Blob
21
const blob = await chart.exportToBlob({ format: 'png', pixelRatio: 2 });