F
Filament15mo ago
awsqed

Register new chart type

How to register new chart type from the community? I installed the new chart type package and tried to register it like this but still got the error.
import './bootstrap';
import Chart from 'chart.js/auto';
import {TreemapController, TreemapElement} from 'chartjs-chart-treemap';

Chart.register(TreemapController, TreemapElement);
import './bootstrap';
import Chart from 'chart.js/auto';
import {TreemapController, TreemapElement} from 'chartjs-chart-treemap';

Chart.register(TreemapController, TreemapElement);
Uncaught Error: "treemap" is not a registered controller.
Uncaught Error: "treemap" is not a registered controller.
I think because I register to the wrong one, not the chart object Filament is using to render chart, but I don't know how to get the right one.
5 Replies
Mads Møller
Mads Møller15mo ago
I have a vey similar challenge, as I want to register a chartjs plugin.
import { Chart } from 'chart.js';
import annotationPlugin from 'chartjs-plugin-annotation';

Chart.register(annotationPlugin);
import { Chart } from 'chart.js';
import annotationPlugin from 'chartjs-plugin-annotation';

Chart.register(annotationPlugin);
awsqed
awsqedOP15mo ago
@Mads Møller i have to copy the chart.js file in vendor, add the register code, then build it with esbuild, then use filament asset to publish it to public folder 1. install chartjs and plugin via npm 2. copy vendor/filament/widgets/resources/js/components/chart.js to resources/js folder 3. follow these steps: https://filamentphp.com/docs/3.x/support/assets#asynchronous-alpinejs-components 4. copy vendor/filament/widgets/resources/views/chart-widget.blade.php to resources/views/vendor/filament-widgets/chart-widget.blade.php 5. replace line 38 with ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('chartjs') }}"
maltebaer
maltebaer12mo ago
awesome, thank you @awsqed! one note: for me to get it working i had to copy the view into resources/views/vendor/filament-widgets/chart-widget.blade.php.
awsqed
awsqedOP12mo ago
@maltebaer oh yeah my mistake, missing the views in path
mxhln87
mxhln878mo ago
thanks, some one need to add this to the docs please

Did you find this page helpful?