To implement several datasets in a chart it is enough to assemble the array that composes the variable datasets in the general data of the graph.
I will try to exemplify with your code what is required to implement:
var arrayDataSets = [];
var dataSetAux = {};
jQuery.each(data, function(index, value){
dataSetAux = {
label: value.anioTtile, //Dependiendo de como este tu objeto de datos, aquí iría el nombre del año.
backgroundColor: ["rgba(151,187,205,1)", "rgba(0, 150, 38, 0.78)", "rgba(36, 133, 2, 0.78)", "rgba(37, 0, 98, 0.78)", "rgba(101, 7, 112, 0.78)"],
borderColor: ["rgba(151,187,205,1)", "rgba(0, 150, 38, 0.78)", "rgba(36, 133, 2, 0.78)", "rgba(37, 0, 98, 0.78)", "rgba(101, 7, 112, 0.78)"],
pointBorderColor: "rgba(12, 95, 142, 0.78)",
pointBackgroundColor: "rgba(38, 185, 154, 1)",
pointHoverBackgroundColor: "rgba(#0b357e, 0.85)",
pointHoverBorderColor: "rgba(8, 171, 171, 1)",
borderWidth: 5,
lineTension: 0,
fill: false,
data: value.anioData//Dependiendo de como este tu objeto de datos, aquí iría el arreglo de los datos de ese año.
}
arrayDataSets.push(dataSetAux);
}
var buyerData = {
labels: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
datasets: arrayDataSets
};
I am omitting part of the code that does not have as much to do with what you need to solve.
Important parts:
value.anioTitle
Name of the year that comes in the object, this data could be checked beforehand with a validation of the index in the array if you do not want to redo the object data
to add a title that identifies the year.
value.anioData
Here you would add each of the specific data for each year for the dataset.
datasets: arrayDataSets
The datasets attribute is waiting to receive an array of all datasets, so we assembled it in the previous cycle to deliver it at this point.
Additionally, if you want to change the colors or other variables within the cycle, you can check the index
within the foreach to know which ones you are in and what value those attributes must have to change it or define that or more attributes of the dataset.