Charts advanced usage
Bootstrap 5 Charts advanced usage
This documentation provides examples of advanced chart usage.
Note: Read the API tab in the basic chart docs to find all available options and advanced customization
*
*
UMD autoinits are enabled
by default. This means that you don't need to initialize
the component manually. However if you are using MDBootstrap ES format then you should pass
the required components to the initMDB
method.
Options
In most cases, working with advanced charts is related to the handling of options.
MDB provides default options for each chart - you can easily change that by passing an object with your custom options to the Chart constructor.
Mixed
With MDB it is possible to create mixed charts that are a combination of two or more different chart types. A common example is a bar chart that also includes a line dataset.
Double Y axis
In the example below we created chart with double Y axis with 2 datasets, each one with completely different data range.
In this setup, we need to tweak the scale. The left axis is set up and adjusted for the first dataset, while the right axis is designated for the second dataset.
Funnel
Example of horizontal bar chart with custom options and labels formatting (calculating integers numbers into percentages).
This data visualization is often used to visualize the flow of the website traffic.
To add datalabels it is necessary to import chartjs-plugin-datalabels
and chart.js
. CDN links are included in HTML snippet.
Formatting values on the Y axes
In the example below we simply add "$" before each value on the Y axis.
Formatting values in the tooltips
In the example below we simply add "$" before each value displayed in the tooltips.
Hover over the chart line to view the tooltip.
Double datasets in a bar chart
Example of the double datasets in a bar chart.
Async data
Example of the fetching data from the JSON file.