I’m trying to make a simple chart using the Charts plugin with the Dataview plugin.
The goal is to supply it a list of notes, check a specific metadata field (“Type”) and count how many notes I have for each unique value of that property
Here’s my code:
const pagesPath = '"Folder"'; //path-filter of notes to process
let types = []; //stores data in associative array
let labels = []; //stores labels for the chart
var files = dv.pages(pagesPath);
for (let i = 0 ; i < files.length ; i++){
let f = fiches[i];
if(types.hasOwnProperty(f.type)){
//we already have encountered the key, increment
types[f.type]++;
} else {
//key is not in the array, add it to the array and the label list
labels.push(f.type);
types[f.type] = 1;
}
}
//display the chart
const barChart = {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Count',
data: types,
borderWidth: 1
}]
}
}
window.renderChart(barChart, this.container);
The chart itself and the labels kind of display correctly (some notes having a blank/missing metadata field might make it glitch) but that’s pretty much it and I’m having a lot of trouble understanding why.