Skip to content
Shamar

ChartWidget

From the /demo dashboard widget grid.
export class VisitsChartWidget extends ChartWidget {
static override heading = 'Daily visits (30 days)'
static override type = 'line'
static override library = 'apex'
static override async data(ctx) {
return {
labels: ['Mon', 'Tue'],
datasets: [{ label: 'Visits', data: [12, 19], color: '#286291' }],
}
}
}

Pass a top-level colors array aligned with labels (preferred). Apex and Chart.js both honor it — no host updateOptions patch required.

return {
labels: ['Present · 12 (80%)', 'Absent · 3 (20%)'],
datasets: [{ label: 'Roll', data: [12, 3] }],
colors: ['#2E7D32', '#B3261E'],
}

Alternatively set datasets[0].colors (or datasets[0].color as a string[]) to the same length, or one color string per dataset when each slice is its own dataset.

Methods

MethodDescription
static typeline | bar | area | pie | donut.
static libraryapex (default) or chartjs.
static data(ctx)Chart payload (async). Prefer `colors` for pie/donut slices; `datasets[].color` for series.
static columnSpan / headingLayout.