Chartjs-How to assign an array to data of charts.js's counts

1👍

Have you tried this ? this.lastSeenDeviceCount.map(element => element.length)

1👍

You can do this;

let devices = []; // array to store all devices
this.lastSeenDeviceCount.forEach(element => {
  devices.push(element.length)
})

datasets: [
  {
    data: devices,
    backgroundColor: "#007BA7",
    hoverBackgroundColor: "#00CC99"
  }
]

What’s happening here is that;

  1. You created an array
  2. You populated the array from the loop logic
  3. Then you pass the value of the array to the chartJs data property to populate the chart

Leave a comment