How do i use the numbers i key in from a form as the input data for chartjs

๐Ÿ‘:0

The data array is expecting an array with values so if you remove your join it should work.

You would get this:

var Diadata = []
 function getdata() {
      Diadata[0] = document.getElementById('Carat').value;
      Diadata[1] = document.getElementById("Cut").value;
      Diadata[2] = document.getElementById("Color").value;
      Diadata[3] = document.getElementById("Clarity").value;
      Diadata[4] = document.getElementById("Depth").value;
      Diadata[5] = document.getElementById("Table").value;
      Diadata[6] = document.getElementById("X").value;
      Diadata[7] = document.getElementById("Y").value;
      Diadata[8] = document.getElementById("Z").value;
 }


getdata();
var ctxL = document.getElementById("barChartHorizontal").getContext('2d');
var myLineChart = new Chart(ctxL, {
  type: 'horizontalBar',
  data: {
    labels: ["Carat", "Cut", "Color", "Clarity", "Depth", "Table", "X", "Y", "Z"],
    datasets: [
      {
        label: "Price",
        data: Diadata, //i want to add my input data here
        backgroundColor: 'orange',
        borderWidth: 0,
      }
    ]
  },

Leave a comment