Getting started
Filament comes with many “chart” widget template, which you can use to display real-time, interactive charts. Start by creating a widget with the command:LineChartWidget class for this example.
The getHeading() method is used to return a heading that describes the chart.
The getData() method is used to return an array of datasets and labels. Each dataset is a labelled array of points to plot on the chart, and each label is a string. This structure is identical with the Chart.js library, which Filament uses to render charts. You may use the Chart.js documentation to fully understand the possibilities to return from getData(), based on the chart type.
Available chart types
Below is a list of available chart widget classes which you may extend, and their corresponding Chart.js documentation page, for inspiration what to return fromgetData():
Filament\Widgets\BarChartWidget- Chart.js documentationFilament\Widgets\BubbleChartWidget- Chart.js documentationFilament\Widgets\DoughnutChartWidget- Chart.js documentationFilament\Widgets\LineChartWidget- Chart.js documentationFilament\Widgets\PieChartWidget- Chart.js documentationFilament\Widgets\PolarAreaChartWidget- Chart.js documentationFilament\Widgets\RadarChartWidget- Chart.js documentationFilament\Widgets\ScatterChartWidget- Chart.js documentation
Generating chart data from an Eloquent model
To generate chart data from an Eloquent model, Filament recommends that you install theflowframe/laravel-trend package. You can view the documentation.
Here is an example of generating chart data from a model using the laravel-trend package:
Filtering chart data
You can set up chart filters to change the data shown on chart. Commonly, this is used to change the time period that chart data is rendered for. To set a default filter value, set the$filter property:
getFilters() method to return an array of values and labels for your filter:
getData() method:
Live updating (polling)
By default, chart widgets refresh their data every 5 seconds. To customize this, you may override the$pollingInterval property on the class to a new interval:
Setting a maximum chart height
You may place a maximum height on the chart to ensure that it doesn’t get too big, using the$maxHeight property:
Setting chart configuration options
You may specify an$options variable on the chart class to control the many configuration options that the Chart.js library provides. For instance, you could turn off the legend for LineChartWidget class: