JavaScript Events
Available since version 2.0. These are native CustomEvent events dispatched on the chart's <canvas> element on the front end.
m_chart.render_done
Fired on the canvas element after the chart has finished rendering. event.detail carries the post ID and instance number; use Chart.getChart( event.target ) for the Chart.js instance. With Defer Rendering enabled (the default), the event fires only once the chart scrolls into view. Reduced-motion users get the event too.
document.querySelectorAll( 'canvas.m-chart' ).forEach( ( canvas ) => {
canvas.addEventListener( 'm_chart.render_done', ( event ) => {
const { post_id, instance } = event.detail;
console.log( 'Chart', post_id, 'instance', instance, 'rendered' );
} );
} );
event.detail properties:
post_id(int) — The chart post IDinstance(int) — The instance number
Fires on its own canvas since 2.4
Before 2.4 each chart dispatched the event on every canvas.m-chart on the page, each carrying its own post_id. Since 2.4 it fires only on the canvas that rendered. Listeners on individual canvases get exactly one event per chart.
Iframe embeds
With the Embeds setting on, the canvas lives inside the iframe document. Listeners on the parent page never receive these events. Inline scripts inside the iframe are blocked by its Content Security Policy, so enqueue your listener through m_chart_iframe_scripts.
Highcharts
The Highcharts Library plugin dispatches its own m_chart.render_done event with the Highcharts chart instance included in event.detail, and an additional render_start event before rendering begins. The core Chart.js dispatch does not expose the chart instance on the event — see Highcharts JavaScript Events for the Highcharts-specific event shapes.
Same name as the admin wp.hooks action
The front-end CustomEvent m_chart.render_done and the admin-side wp.hooks action m_chart.render_done are intentionally identically named — same semantic event ("the chart has finished rendering") exposed through two different mechanisms (a DOM CustomEvent on the front end, a wp.hooks action in the admin React app). Listen via canvas.addEventListener( 'm_chart.render_done', ... ) on the front end and wp.hooks.addAction( 'm_chart.render_done', ..., callback ) in the admin.
M Chart Pro tables
On a chart using M Chart Pro's Display as Table, m_chart.render_done and the deprecated render_done fire on the <table class="m-chart-pro-table"> element instead of a canvas, with the same event.detail shape. The events bubble, but a canvas.m-chart selector will not find them; listen on the chart container or on document.
Deprecated event name: render_done
Prior to v2.0, the v1.x jQuery event was named only render_done (no namespace). That name is still dispatched for backward compatibility but is deprecated and will be removed in v3. Update any listeners to use m_chart.render_done instead.
Migrating from v1
In v1.x these events were jQuery custom events (.on('render_done', ...)). In v2.0+ they are native CustomEvent events dispatched on the canvas element. Event data is accessed via event.detail rather than the jQuery handler arguments. See Migrating to v2.
MChartHelper helpers
window.MChartHelper is the Chart.js plugin M Chart registers on every chart. Since 2.4 it also exposes a few functions for front end code.
MChartHelper.formatValue( chart, value, affixes )
Format a value the way M Chart's tooltips and data labels do. Pass a parsed data point from a dataset's rawData ({ value, prefix, suffix, text }) or a plain number with optional { prefix, suffix }. The chart's options.locale drives the number formatting.
canvas.addEventListener( 'm_chart.render_done', ( event ) => {
const chart = Chart.getChart( event.target );
const raw = chart.data.datasets[ 0 ].rawData[ 0 ];
console.log( MChartHelper.formatValue( chart, raw ) ); // "$1,234.5"
console.log( MChartHelper.formatValue( chart, 7, { suffix: '%' } ) ); // "7%"
} );
MChartHelper.dispatchRenderDone( el, detail )
Dispatch m_chart.render_done and the deprecated render_done on one element, bubbling, with the given event.detail. Plugins that render a chart's data some other way can fire the same events core does.
MChartHelper.dispatchRenderDone( tableElement, { post_id: 12, instance: 1 } );
MChartHelper.treemapSourceEntry( raw )
Available since version 2.4.2.
Get the source row behind a treemap rectangle. Pass the rectangle's raw object (context.raw in a scriptable option, item.raw in a tooltip callback, element.$context.raw on a drawn element). In a grouped treemap a rectangle below the top level only carries the group fields from its own level down, so this returns the first of the rows the rectangle was built from, which has every field, including the names of the groups above it. In a flat treemap it returns the rectangle's own row. Returns null when there is no data to read.
canvas.addEventListener( 'm_chart.render_done', ( event ) => {
const chart = Chart.getChart( event.target );
const groups = chart.data.datasets[ 0 ].groups || [];
chart.getDatasetMeta( 0 ).data.forEach( ( element ) => {
const row = MChartHelper.treemapSourceEntry( element.$context.raw );
// The top-level group this rectangle sits in, whatever its own level
console.log( row && row[ groups[ 0 ] ] );
} );
} );
MChartHelper is only loaded when the chart is drawn by Chart.js, see m_chart_render_uses_chartjs.
Internal Events
These events are dispatched by the admin UI for its own coordination. They are not part of the public API — names, payload shapes, and the fact that they exist at all are subject to change without notice. Extensions should not depend on them.
m-chart-tab-nav— Bubbled from individual sheet tab elements to coordinate cross-tab keyboard navigation (Arrow keys, Home, End) in the multi-sheet tab bar.