Here is what I've done so far
function setcanvas(ID,Count,Count1,Count2,Count3,Count4,Count5,Count6,Count7,Count8,Count9,Count10){
var ctx = document.getElementById(ID).getContext('2d');
ctx.canvas.width = 350;
ctx.canvas.height = 300;
var arr=[];
var y=1;
var str = "Count";
while(y <= Count){
var str2 = str + y;
arr.push(str2);
y++;
}
}
I expect the value of my array to be the value on the parameters but Its not. Instead the values I see are Count1, Count2, Count3 .... Can someone explain this to me and are there any way to achieve this goal ?
Solution Found
Thanks from the comment below. I've come up with this solution.
function setcanvas(ID,Count,Count1,Count2,Count3,Count4,Count5,Count6,Count7,Count8,Count9,Count10){
var ctx = document.getElementById(ID).getContext('2d');
ctx.canvas.width = 350;
ctx.canvas.height = 300;
var myBarChart = new Chart(ctx, {
type: 'horizontalBar',
data: {
labels: ["Analytics 1", "Analytics 2", "Analytics 3", "Analytics 4", "Analytics 5"],
datasets: [{
label: "Count",
data: getCountByArguments(Count1, Count2, Count3, Count4, Count5, Count6, Count7, Count8, Count9, Count10),
backgroundColor: setUpBC(Count)
}]
},
options: {}
});
function getCountByArguments(){
var arr = [];
var i=0;
while(i < Count) {
arr.push(arguments[i]);
i++;
}
return arr;
}
}
Added the function getCountByArguments