BarChart renders a bar (or column) chart using ApexCharts.
Data is loaded via AJAX and the chart supports horizontal mode, axis formatting, data labels, and tooltips.
Import
import {components} from 'metronic-extension';
const {BarChart} = components;
Constructor
new BarChart(element, options)
Parameter
Type
Description
element
string | HTMLElement
CSS selector string or HTMLElement for the chart container.
options
BarChartOptions
Chart configuration options (see below).
BarChartOptions
Property
Type
Default
Description
horizontal
boolean
false
If true, renders a horizontal bar chart instead of vertical columns.
ajax.method
'GET' | 'POST' | 'PUT'
'GET'
HTTP method for the data request.
ajax.url
string
-
URL to fetch chart data. Required.
ajax.data
(data: object) => object
-
Callback to modify request data before sending.
ajax.dataSrc
(data) => BarChartResponse[]
-
Callback to transform the response data.
xAxisFormatter
(value) => string
-
Formats X-axis label display values.
yAxisFormatter
(value) => string
-
Formats Y-axis label display values.
dataLabelFormatter
(value) => string | number
-
Formats the value displayed on each bar.
tooltipDataFormatter
(value) => string
-
Formats the tooltip data value.
Methods
Method
Return
Description
reload()
Promise<void>
Reloads chart data from the server and redraws the chart.
Data Format
The server should return an array of BarChartResponse objects:
// BarChartResponse
{
category: string; // Category label (X-axis)
name: string; // Series name (legend)
data: number; // Value
color?: string; // Optional bar color (hex)
}
Basic Example
A vertical bar chart with multiple series, formatted axis labels, and a reload button.