Stat views
With Adomin, you can also easily show graphs, pie charts and other KPI visualizations.
For this, you will need to write some backend configuration, and then the adomin frontend will render your charts with Chartkick, a js chart lib that uses chart.js under the hood.
Types of charts available
Pie chart
Bar chart
Column chart
Line chart
Area chart
Kpi chart
Config
To declare a stat view page, you will need to add a StatViewConfig
object inside the views
array of the app/adomin/config/adomin_config.ts
file.
Use the createStatsViewConfig
function to create your StatViewConfig
object:
The createStatsViewConfig
allows you to pass an object with the stat view configuration.
You can pass the following options inside the config object:
name
Path in the frontend
label
Title of the view, displayed in the sidebar
visibilityCheck
Access check function to verify if logged in user can see this stat view
isHidden
Use this if you want to hide this model on the frontend. Frontend routes for create/update/list will still be created and available, but the navbar won’t show it.
icon
Icon name, by default this uses Tabler icons You can browse the list of available icons at: https://tabler.io/icons
stats
An array of AdominStat
objects, each AdominStat
represent a chart
AdominStat config
The AdominStat
object has the following properties
type
Type of the chart to display, can be one of:
- pie
- bar
- column
- line
- area
- kpi
label
Label of the stat, displayed in the frontend
name
Name of the stat must be unique on the page, it is not shown to the user but used in things like react key
prop
dataFetcher
Function to fetch the data to displayed in the chart, must return a Promise<ChartRowData>
In practice it will look like this:
- data of the column chart example
- data of the line chart example
options
When stat type is pie
, bar
, column
, line
or area
you can pass the following options inside the config object:
When stat type is kpi
you can pass the following options inside the config object:
Data fetcher helpers
For basic charts, you can use these functions in your dataFetcher
function:
- groupByDayOfWeek
- groupByDate
- groupByYear
- groupByMonth
- groupByHour
The signature of these functions is
only groupByHour differs slightly with an optionnal 3rd parameter:
In practice, you can use the data fetcher helper like this:
With multiple data series:
See the source code
Directoryapp
Directoryadomin
- create_stats_view_config.ts Open on GitHub
Directoryroutes
Directorystats
Directoryhelpers
- group_by_helpers.ts Open on GitHub
- get_cumulative_table_data.ts Open on GitHub
- instance_metrics.ts Open on GitHub