Creating Dynamic Graphs in Obsidian

A decorative graph on paper, symbolizing graphs in Obsidian.

Obsidian has an incredible plugin ecosystem. Not only are the plugins individually impressive, but sometimes they integrate with each other in unexpected and wonderful ways. One of my favorites gives us the ability to create graphs in Obsidian.

This trick involves two community plugins: Dataview and Obsidian Charts. Dataview gives you ability to query almost anything you could want, and Charts allows you to plot that data on a graph. We can get into all kinds of trouble if we connect those two things.

What graphs in Obsidian look like

If you’re like me, you might not get how useful dynamic graphs are until you’re given some concrete examples. Fair enough!

There are all sorts of things you can track in Obsidian using these two plugins. In my own vault, here are a few of the things I use it for:

  • Visualizing writing projects
  • Tracking daily habits
  • Tracking task completions
  • Tracking the growth of my Zettelkasten

We’ll talk about each of these in more depth below. For the purposes of this article I’m not going to go into how to set up these individual graphs. I’d just like to show you some of what is possible using these two plugins.

Basic bar charts in Obsidian

In order to create a chart with these plugins, you need to be familiar with DataviewJS and chart.js.

DataviewJS is a JavaScript API provided by Dataview. It allows you to query your vault using JavaScript, which gives you a ton of power and flexibility. If you know JavaScript, then this should be pretty easy to pick up.

As for chart.js, that is the library that Obsidian Charts uses, you can see the full chart.js documentation here. You can do some incredibly complex things with this library, but we’re going to start simple.

In my experience, the easiest chart to start with is the basic bar chart. Here’s the code required to create a bar chart, and what it looks like in Obsidian:

const labels = ['One', 'Two', 'Three'];
const data = [1, 2, 3];

const chartData = {  
    type: 'bar',
    data: {
        labels: labels,
        datasets: [{
            label: 'Numbers',
            data: data

window.renderChart(chartData, this.container);
A simple bar chart in Obsidian.

In order to create this type of chart, you need two pieces of data: labels and data. In the example above, those are stored in the variables called labels and data. They are both arrays that contain three items, and our chart represents that in the manner above.

The trick is creating those two variables dynamically instead of statically. I manually typed out the arrays above, but we can do better, and that is where DataviewJS comes in.

Visualizing writing projects with graphs

DataviewJS is the key to making dynamic graphs in Obsidian. The trick is formatting it so that Obsidian Charts can process it.

One way you can use a bar chart is to track the relative sizes of writing projects. This is a quick-and-dirty way to gauge how far along different projects are.

We’ll start by fetching notes with a certain tag in them:

const tagPages = dv.pages('#writing/idea');

Next we need to format the data for the chart. To do that, we create two different arrays and use a loop:

var labels = [],
    wordCount = [];

// Loop through every note and add data to the above arrays
tagPages.forEach(note => {
    // add the name of the note
    // add the word count for the note

Then we use that data in our chart:

const chartData = {  
    type: 'bar',
    data: {
        labels: labels,
        datasets: [{
            label: 'File Size',
            data: wordCount

window.renderChart(chartData, this.container);

In my own vault, the results of that code look something like this:

A dynamic bar chart in Obsidian that shows the relative lengths of articles I've been writing.

Pretty neat, eh? You can use this same code to display any of the built in values that Dataview indexes.

Creating a daily habits graph in Obsidian

Another great use for graphs in Obsidian is tracking daily habits.

There are a few more prerequisites for this one:

  • You must be using the core Daily Notes plugin
  • You must add your own metadata to each note

I add the metadata to a template for my daily notes, which looks something like this:

## Daily Questions
Today did I...
- Read::0
- Workout::0
- Pray::0

## Journal Entries

Note: Dataview allows you to create metadata by adding two colons after any text. Examples above include “Read”, “Workout”, and “Pray”, all of which have the value “0”. To complete a habit, I change the 0 to a 1.

Once you have this metadata in your notes, you can start to pull it into graphs.

There are a couple of different ways you can visualize this information. If you have multiple habits you want to track, then perhaps the simplest method would be to use a bar chart:

An example bar chart showing habit completions.
Uh oh: looks like I better get back on my workout game.

I also like a line chart for habits. You can either design the chart to be cumulative, or you can do a “streak counter”, where your progress goes back to zero if you miss a day (I find this method is more motivating):

An example streak counter in Obsidian.
My longest streak this year is only eight days: another thing I should try to improve!

These two graphs are more complicated to set up, but it’s a great way to visualize how consistent you are at completing habits over time.

Tracking task completions with graphs

I’m a big fan of managing tasks in Obsidian. One reason why is the flexibility that Obsidian provides. You can fine-tune your task system to work exactly how you want it to work.

You can also create your own custom data visualizations. For task management, I’m a big fan of tracking task completions over time. This allows you to get a rough idea of whether your task system is working or not.

I like to track both daily task completions and monthly. I find both of these visualizations useful, and I reference them frequently:

An example graph that shows completed tasks in Obsidian.

Tracking the growth of a Zettelkasten with graphs

A while back I wrote about Getting Started with Zettelkasten. When I started building a Zettelkasten, I wanted a concrete way to visualize how my atomic notes grew over time. To do that, I turned to charts.

I ended up with two charts: one is cumulative and the other is a daily report. Here’s what each looks like:

Zettelkasten analytics in Obsidian.

In this case I also added a table above the graphs that gives me more direct access to recently created notes. I find this useful, as there’s no way to explore notes within the graphs. They are strictly visualizations.

In conclusion

Dynamic graphs can be a little complex to set up, but they’re a great way to get extra value out of all the data you’re creating within your vault. Hopefully this article has given you some ideas for how graphs could help in your vault.

If you want more details about any of the above graphs, let me know, and we can provide a deeper dive into the details.

One response to “Creating Dynamic Graphs in Obsidian”

  1. Hi Tim, I found your plots of completed tasks and created notes plot interesting.

    Would you mind sharing the code to create the plots in section Tracking task completions with graphs and Tracking the growth of a Zettelkasten with graphs.


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: