Chartjs-Show multiple charts at HTML page?

0👍

Is the data the user sends you as the data1 object? Do you always need a pie chart? If so…

function createChart(data, id) {
  addCanvas(id); // some id generated by you or sent by the user
  generateChart(data, id); // data from the user
}

function addCanvas(id) { // create the new canvas
  let canvas = document.createElement("canvas");
  canv.setAttribute("id", "canvasID");
  document.getElementsByClassName('pie-chart-container')[0].appendChild(canvas);
}   

function generateChart(data, id) { // initialize the new chart 
  let piechart = $("#" + id);
  let chart = new Chart(piechart,{
    type:"pie",
    data : data,
    options: {
      title: {
        display: true,
        text: namesArr[0]
      }
    }
  });
}

Leave a comment