I usually track my day in a daily note using custom attributes. I needed a way to visualize the correlation between these attributes, so I created this simple plug.
For example, I use these custom attributes in the front matter of my daily notes:
attribute:
mood: 7
hoursOfExercise: 1
To create a chart I add this widget:
```attributeChart
query:
page where name =~ /^Journal\/Day\//
attributes:
- name: hoursOfExercise
type: line
- name: mood
type: line
```
page where name =~ /^Journal\/Day\// and attribute.mood != undefined
You can create as many charts as you want on a page using fenced code blocks. Currently, the plug just extracts attribute values into an array and uses Chart.js to draw the charts. It only works with the types line and bar. I haven’t tested it with other chart types, but to draw other types, we may need to organize the data differently.
I am 100% sure I tried that query, using attribute.mood but I am not sure why it didn’t work then.
Maybe i needed a full Reload or something to get it working.
page where
name =~ /^Journal\/Day\// and
attribute.mood != undefined and
niceDate(created) >= "2024-09-1" and
niceDate(created) <= "2024-09-30"
Updated: I missed that you mentioned “The last x days”. That requires some calculations with the current date. Something similar to the “DaysTillDate” template function that people shared. However, I don’t think we can call a custom function in a query.
Your query didn’t work for me but I found a way it throws results:
query:
page where name =~ /^Journal\/Day\/2024/
and attribute.mood != null
and "{{niceDate(created)}}" >= "2024-09-01"
and "{{niceDate(created)}}" <= "2024-09-30"
However the filtering doesn’t seem to work. No matter which dates I add, I always get all of them.
I confirmed that
```template
{{niceDate(created)}}
```
throws a date in each of the Journal pages.
Now, even if this works, I see a small caveat. I not always create the Journal date on the exact date, soemetimes i forget, or I am away from computer, and i create the journal date entry a couple of days later.
using niceDate(created) would use the creation date and not the Journal date per se.
I think your issue with the Journal date is not created date is already solved by my mistake . When creating the plug I used the page name for the x axis instead of the created date.
I’m thinking of supporting a date range option such as “fromDate - toDate" or “last 30 days” … (well when I have time to work on it)
Thanks!
This works with created.
I guess I’ll have to be mindful of always creating the journal dates in the right moment, but this should do a much better job than having nothing as even if i missed the creation for a few days, it allows me to plot the chart with way lower points, aiming at something like ~30 days or so (at some point it doesn’t matter if i render 30, 28 or 35 )