February 2019
Beginner to intermediate
284 pages
6h 20m
English
You can add more datasets to a bar chart, and configure it with a new legend label, colors, and data arrays. In the following example, we will load a larger .csv file, which contains the data for plastic waste disposal in 2010, and a forecast for 2025. It has one extra column, as follows:
Country,2010,2025 China,8819717,17814777 Indonesia,3216856,7415202 Philippines,1883659,5088394 ... United States,275424,336819
This time, the code will generate two data arrays and a single labels array. The data and labels that belong to the same category have the same index, as follows:
fetch('../Data/waste2.csv') .then(response => response.text()) .then((data) => { const labels = [], values2010 = [], values2025 = []; const rows ...Read now
Unlock full access