F
Filament4mo ago
morty

Where to put custom JavaScript? `resources/js/app.js` doesn't seem to work?

I'm trying to add some custom js in my app.js file but it doesn't seem to load. I'm running npm run build after to be sure and still nothing. Even something as simple as console.log('Hello, World!'); isn't showing in the console. I do have a custom theme file but this is just for style overrides right? Or do I need to do something for JS too? To be more specific, I'm trying to enable chart.js auto colors: https://www.chartjs.org/docs/latest/general/colors.html#default-color-palette
Colors | Chart.js
Open source HTML5 Charts for your website
7 Replies
Alex-Elivate
Alex-Elivate4mo ago
You can set chart widget options https://filamentphp.com/docs/3.x/widgets/charts#setting-chart-configuration-options And/or add javascript to custom pages https://livewire.laravel.com/docs/javascript There is also a great series on how to create your own components https://laracasts.com/series/build-advanced-components-for-filament Also for Chart.js plugins give this a read: https://filamentphp.com/docs/3.x/widgets/charts#using-custom-chartjs-plugins
Dennis Koch
Dennis Koch4mo ago
Registering custom JS wouldn't be of much use in this case. You can pass custom options for ChartJS via the getOptions() method on the ChartWidget class
Alex-Elivate
Alex-Elivate4mo ago
Oops, that plugin is already installed. @Dennis Koch answer stands. lol
morty
mortyOP4mo ago
But I can't enable the built in chartjs plugin through options because it isn't registered
Alex-Elivate
Alex-Elivate4mo ago
My bad, chart.js doesn't have the autocolors plugin installed, it has the colors plugin, you have to register autocolors using the pattern. https://filamentphp.com/docs/3.x/widgets/charts#using-custom-chartjs-plugins https://stackoverflow.com/questions/74618957/chartjs-autocolors-not-working-as-expected-with-dataset

Did you find this page helpful?