Creating a bar chart
A bar chart displays a list of categories associated with values represented by the length of the bars. To create a simple bar chart, we need a list of categories, as well as list of values.
Let's create a simple chart to display the volume of water in each ocean. We will need an array of categories, as follows:
const labels = ["Arctic", "North Atlantic", "South Atlantic", "Indian", "North Pacific", "South Pacific", "Southern"];
In addition, we will also need a corresponding array of values, as follows:
const volumes = [18750,146000,160000,264000,341000,329000,71800]; // 10^3 km3
The data
object should contain a labels
property, which will refer to the categories
array, and a datasets
property, which contains an array with at least one dataset
object. Each dataset
object has a label
property, and a data
property, which will receive the data for our chart (the volumes
array), as follows:
const dataObj = { labels: labels, datasets: ...