Custom Chart.js Themes
A Chart.js theme is a PHP file that returns a color palette and, optionally, point styles. Themes added this way appear in the theme selector on each chart edit screen and in the Default Chart.js Theme setting, next to the built-in themes. Site owners who prefer a visual editor can use M Chart Pro's Theme Builder instead.
Theme files
Create custom themes by adding PHP files to an m-chart-chartjs-themes directory inside your active WordPress theme folder:
wp-content/themes/your-theme/
└── m-chart-chartjs-themes/
└── my-theme.php
A theme file returns an array with colors and optionally points:
<?php
/**
* Theme Name: My Custom Theme
*/
return [
'colors' => [
'#e63946',
'#457b9d',
'#2a9d8f',
'#e9c46a',
'#f4a261',
'#264653',
],
];
Point Styles
Optionally customize the point markers used on line/scatter charts:
<?php
/**
* Theme Name: My Custom Theme
*/
return [
'colors' => [ '#e63946', '#457b9d' ],
'points' => [
[ 'point' => [ 'pointStyle' => 'circle' ] ],
[ 'point' => [ 'pointStyle' => 'rect' ] ],
[ 'point' => [ 'pointStyle' => 'triangle' ] ],
],
];
Once your file is in place, the theme will appear in the theme selector on each chart edit screen and in the default theme setting.
Registering themes with a filter
The m_chart_chartjs_themes filter adds a theme to the dropdowns without a file. The theme lookup at render time reads the theme directories only and does not consult that filter. A filter-only theme therefore needs a companion m_chart_chart_args filter that applies its options when the chart's theme slug matches.