What I’m trying to do
I’m trying to create a line chart where:
- The x-axis are the days of the month,
- The y-axis is how long I spend meditating,
- There is a different line for each month in the year.
I’m struggling with:
- Developing an array for the month (where missing or empty daily notes = 0)
- A better way of grouping/filtering by month
YAML and File Structure
YAML
In my Daily Notes, I track this within the YAML:
---
fitness:
meditation: ##
category: daily
date: yyyy-mm-dd
---
File Structure
My Daily Notes are gathered in a quarterly file structure, so I have to filter for notes in 2023.
- 202 BuJo
– 202.12 Daily
— 21 Notes
— 22 01-03 Notes (etc)
— 22 10-12 Notes
— 23 01-03 Notes
— 23 04-06 Notes
Things I’ve tried
Line graph for all of 2023 - success
The first thing was building a standard line graph across all of 2023.
const pages = dv
.pages('"202 BuJo/202.12 Daily"')
.where((page) => dv.func.contains(page.file.name, "2023-"))
.where(p => p.fitness.meditation)
.sort(p => p.date, 'asc')
const testNames = pages.map(p => p.file.name).values
const testMarks = pages.map(p => p.fitness.meditation).values
const chartData = {
type: 'line',
data: {
labels: testNames,
datasets: [{
label: 'Mark',
data: testMarks,
backgroundColor: [
'rgba(255, 99, 132, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)'
],
borderWidth: 1,
}]
}
}
window.renderChart(chartData, this.container)
This renders out just fine!
Multiple months, and an array - but skips the missing days
I developed my initial query to have preassigned labels, and am able to have each month as their own line!
However, the value wasn’t ‘0’ on missing days - they were just skipped.
Also, I am wondering if there’s a simpler way of doing this - rather than having each month as its own element, but something closer to DataviewJS and Charts: split by frontmatter variable ("Medium") ?
var labels = ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31",];
const cardSix = dv
.pages('"202 BuJo/202.12 Daily"')
.where((page) => dv.func.contains(page.file.name, "2023-06"))
.where(p => p.fitness.meditation)
.sort(p => p.date, 'asc')
const monthsix = cardSix.map(p => p.fitness.meditation).values
const cardFive = dv
.pages('"202 BuJo/202.12 Daily"')
.where((page) => dv.func.contains(page.file.name, "2023-05"))
.where(p => p.fitness.meditation)
.sort(p => p.date, 'asc')
const monthfive = cardFive.map(p => p.fitness.meditation).values
const chartData = {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'June',
data: monthsix,
backgroundColor: ['#ffa244'],
borderColor: ['#ffa244'],
borderWidth: 1
},
{label: 'May',
data: monthfive,
backgroundColor: ['#69EDFF'],
borderColor: ['#69EDFF'],
borderWidth: 1
}]
},
}
window.renderChart(chartData, this.container);
Next Steps?
Both of my struggles feel like they should be solved by:
- Identifying the day and the month of each daily note,
- Grouping / Filtering each month to become its own line,
- Then sorting the values by day, correlated to the provided array.
- Each month will then be its own element in ‘data’.