Chartjs-Line chart with a lot of data: skip labels

0👍

Use an array that stores all values you have (if you want to update your chart, display other values or to reduce AJAX calls). Then use another array with the data you want to display. You need an appropriate function to copy and filter your old array.

Here I use every fifth element:

let delta = 5
let displayedData = []
for (let i = 0; i < allData.length; i=i+delta) {
  displayedData.push(allData[i]);
}

You can calculate the delta in a different way or use a completely different approach to get your data.

Side note: don’t use .filter(), you don’t want to lop through all your data. Use a direct access like I did above.

Leave a comment