JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js">
//this example button has the id of file 'c' as an example for my hardcoded arrays, but this id should be allocated when creating the buttons
//files represents a list of extracted file names from the main data structure
files = ['file_A', 'file_B', 'file_C', 'file_D'];
//contributions represents a list of extracted data related to each of these file names, i.e. the number of total edits made by each user
contributions = [['jack:2', 'yep:4', 'nah:7', 'woo:2'], ['jack:6', 'yep:1', 'nah:8', 'woo:4'], ['jack:7', 'yep:3', 'nah:4', 'woo:6'], ['jack:4', 'yep:2', 'nah:1', 'woo:7']];
function create_pie_chart(drive_name, file_name, users, contributions)
{
var driveName = drive_name; //string taken as paramater
var fileName = file_name; //string taken as parameter
var usersArr = users; //array of strings taken as parameter
var contributionsArr = contributions; //array of ints taken as parameter
var N = usersArr.length; //length of users &/or contributions array
var data = [] //empty array to store users:contributions in required format for graphing
//filling the data array in the required format
for (var i = 0; i < N; i++)
{
data.push({y: contributions[i], indexLabel: users[i]})
}
//test print to see the structure
console.log(data)
//graphing func
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
theme: "theme3", //colour/text selection
title:{
text: "User %/Actions for " + fileName + " in Drive " + driveName
}, //title with parameters
data: [
{
...