0👍
So i think i found the 95% of the solution for this problem.
I created a new array, in wish i push the current count of “occurs” so i have the pair (date – occurrences)
– I now have a minor problem, the last date repeats!! and thats because the last if(count > 0), but if i dont push the year, even i my console log gives the correct array of dates, my char only display 3 (?) Ill post the code and the print od the console log and chart!
ts
let month = [];
let current;
let count = 0;
let year = [];
let values = [];
chartDates = chartDates.sort()
for (var i = 0; i<chartDates.length; i++)
{
month.push(chartDates[i].split('-')[1]);
if (chartDates[i] != current)
{
if (count > 0)
{
//console.log(current + ' times ' + count);
values.push(count);
}
current = chartDates[i];
year.push(current);
count = 1;
}
else
{
count++;
}
}
if (count > 0)
{
//console.log(current + 'times ---' + count);
//year.push(current);
values.push(count);
}
console.log('datas: '+year+ ' contadores '+ count);
chart inside ts
var myChart = new Chart(ctx, {
type: ‘bar’,
data: {
labels: year,
datasets: [{
label: year,
data: values
…
Console log:
datas:
2010-02-08,2010-02-11,2010-03-05,2010-03-08,2017-09-19,2017-12-26
contadores 1
FIX EDIT : if added year.push(current); it will fix, even if it displays last label repeated, but without any value.