Chartjs-How to use chart.js with knockout.js to create dynamic charts

0👍

Hope This will help You …

lineChartData = {
  labels: [],
  datasets: [
    {
      fillColor: "rgba(151,187,205,0.5)",
      strokeColor: "rgba(151,187,205,1)",
      pointColor: "rgba(151,187,205,1)",
      pointStrokeColor: "#fff",
      data: [],
    },
  ],
};
// For Example You receive Data from API is Like this
data = [
  {
    month: "January",
    value: 1,
  },
  {
    month: "February",
    value: 2,
  },
  {
    month: "March",
    value: 3,
  },
  {
    month: "April",
    value: 4,
  },
];
    // Just push received data to labels and data to display dynamically
 for (let i = 0; i < data.length; i++) {
    lineChartData.labels.push(data[i].month)
    lineChartData.datasets[0].data.push(data[i].value)
 }

 console.log('Month ', lineChartData.labels)
 console.log('Value ',lineChartData.datasets[0].data)

Leave a comment