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
In order to use chart directive in your application, install chart.js
(v3) library and import it in angular.json
file. Read the
API tab in the basic chart docs
to find more information about required imports.
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.
Data labels
In order to use datalabels plugins, you need to install chartjs-plugin-datalabels
package. The [plugins]
input used in the example below was added in version 4.0.0. In previous versions the ChartDatalabels
plugin was registered by default.
Use datalabels
plugin to display values directly on a graph.
Double Y axis
In the example below we created chart with double Y axis with 2 datasets, each one with completely different data range.
Such a construction requires a scale adjustment, so the left axis is assigned and adjusted to the first dataset, and the right axis to 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.
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 the line of the chart to see the tooltip.
Double datasets in a bar chart
Example of the double datasets in a bar chart.
Async data
Example of fetching data from the JSON file.