avatarNuno Campos

Summary

The undefined website provides a comprehensive guide on how to incorporate and utilize the Obsidian Charts plugin to create various types of charts within Obsidian notes, enhancing visual data representation.

Abstract

The undefined website article titled "My Obsidian Setup (Part 16) — Charts" explains the process of integrating charts such as line, bar, pie, doughnut, polar area, and radar into Obsidian notes using the Obsidian Charts plugin. The article outlines the basic usage of the plugin, including the necessity of the Dataview plugin for data querying, and demonstrates how to create charts from tables and transform them into images. It also delves into advanced features and settings available for customizing charts, and provides examples of how to use the plugin with DataviewJS for more complex data visualization tasks, such as charting Medium article views over time. The article emphasizes the utility of visual data representation within Obsidian for tracking habits, creating notes, and analyzing data.

Opinions

  • The author, Nuno Campos, advocates for the Obsidian Charts plugin as a powerful tool for data visualization within Obsidian, suggesting it as a valuable addition to one's Obsidian setup.
  • The article implies that the combination of the Obsidian Charts and Dataview plugins significantly enhances the user's ability to work with and visualize data within their notes.
  • The author seems to value the ease of use and versatility of the Obsidian Charts plugin, as evidenced by the step-by-step instructions and examples provided.
  • The inclusion of visual aids, such as screenshots and chart examples, indicates the author's belief in the importance of visual learning and the effectiveness of charts in data communication.
  • By providing a link to the Obsidian Charts plugin documentation, the author encourages readers to further explore and utilize the plugin's full range of capabilities.

My Obsidian Setup (Part 16) — Charts

Ever wanted to include line charts, bar charts, doughnuts, pie, etc. in your notes? You may want to view a chart representation of your habits tracker or when you create notes. The Obsidian Charts plugin lets you include charts in your notes. You will also need Dataview to be able to query values. Let’s check how it’s done.

Photo by fauxels

First, you need to install the Obsidian Charts Plugin.

Basic Usage

A code block of the type chart is used to generate a chart. The chart settings are set using YAML. The properties’ names are self-explanatory.

```chart
    type: ""
    labels: []
    series:
        - title: ""
        data: []
        - title: ""
        data: []
```

You can also use the graphical chart creator from the Command Palette, or even set a Hotkey to create simple charts. Just open the Command Palette and type chart.

Insert new chart from Command Palette. Image by Nuno Campos
Chart creator window. Image by Nuno Campos
Resulting chart. Image by Nuno Campos
Resulting chart YAML properties. Image by Nuno Campos

Chart Types

Bars

The bar chart was already shown above.

Pie

```chart
type: pie
labels: [Monday, Tuesday, Wednesday,Thurday,Friday]
series:
  - title: Read Articles
    data: [12,4,7,5,8]
  - title: Written Articles
    data: [1,0,3,2,1]
width: 80%
labelColors: true
```
Pie Chart. Image by Nuno Campos

Doughnut

```chart
type: doughnut
labels: [Monday, Tuesday, Wednesday,Thurday,Friday]
series:
  - title: Read Articles
    data: [12,4,7,5,8]
  - title: Written Articles
    data: [1,0,3,2,1]
width: 80%
labelColors: true
```
Doughnut Chart. Image by Nuno Campos

Line

```chart
type: line
labels: [Monday, Tuesday, Wednesday,Thurday,Friday]
series:
  - title: Read Articles
    data: [12,4,7,5,8]
  - title: Written Articles
    data: [1,0,3,2,1]
```
Line Chart. Image by Nuno Campos

Polar Area

```chart
type: polarArea
labels: [Monday, Tuesday, Wednesday,Thurday,Friday]
series:
  - title: Read Articles
    data: [12,4,7,5,8]
  - title: Written Articles
    data: [1,0,3,2,1]
labelColors: true  
width: 40%
```
Polar Area Chart. Image by Nuno Campos

Radar

```chart
type: radar
labels: [Monday, Tuesday, Wednesday,Thurday,Friday]
series:
  - title: Read Articles
    data: [12,4,7,5,8]
  - title: Written Articles
    data: [1,0,3,2,1]
width: 80%
```
Radar Chart. Image by Nuno Campos

Create Chart From Table

We can create a chart from a table in the same or another note. Just add a Block ID (^name) to the table and the same id to your Chart codeblock.

```chart
type: line
id: table-test
width: 80%
```
|           | Read | Written |
| --------- | ---- | ------- |
| Monday    | 12   | 1       |
| Tuesday   | 4    | 0       |
| Wednesday | 7    | 3       |
| Thursday  | 5    | 2       |
| Friday    | 8    | 1       | 
^table-test
Chart from table. Image by Nuno Campos

If you want to get the data from a table on a different note, also insert the note name in the file attribute.

For example, a table in a note with the name data-note.md :

```chart
type: line
id: table-test
file: data-note
width: 80%
```

Replace Table with Chart

We can also transform a table into a chart. Just select the table markdown, access Command Palette, a select Obsidian Charts: Create Chart from Table:

Table markdown. Image by Nuno Campos
Command Palette. Image by Nuno Campos
Generated chart codeblock. Image by Nuno Campos
Generated Chart. Image by Nuno Campos

Convert Charts to Images

Converting a chart to an image may also be handy. Select the chart codeblock, access Command Palette and select Obsidian Charts: Create Image from Chart:

Select Chart codeblock. Image by Nuno Campos
Create Image from Chart. Image by Nuno Campos
Generated image. Image by Nuno Campos

Full Settings

  • width — set the width of any Chart
  • fill — is used in Line Charts to fill the Area under the Traces
  • spanGaps — fill in missing Datapoints
  • tension — is used in Line Charts to set the tension of the Traces to the given points
  • beginAtZero — set the Chart to begin at 0
  • legend —toggle the display of the legend
  • legendPosition— where the legend will be displayed
  • indexAxis— sets bar or lines chart orientation horizontal or vertical
  • stacked— sets bar and line graphs stacked
  • Title— use xTitle: “Title here” or yTitle: “Title here” to add a Title to the specified Axis
  • Reverse— reverse the axis it is applied to ( xReverse or yReverse)
  • Minand Max— min and max of the respecitve axis ( xMax ,yMinor rMax for radar and polar area)
  • Display and TickDisplay— toggle the visibility of the axis (Display) or the ticks of the axis (TickDisplay)
  • time— format as day, week, month, year, etc
  • transparency— set transparency of the inner color of your chart’s elements

Advanced

If you want to do more advanced things, you can use the Dataview plugin.

You will also need to understand how DataviewJS works (check here).

If you want to use Charts with Dataview, check this example:

test:: First Test
mark:: 6
```dataviewjs
const data = dv.current()
const chartData = {
    type: 'bar',
    data: {
        labels: [data.test],
        datasets: [{
            label: 'Grades',
            data: [data.mark],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)'
            ],
            borderWidth: 1
        }]
    }
}
window.renderChart(chartData, this.container);
```

Example: Chart For Your Medium Views

Let’s create a chart from a DataView query. Suppose we have a field on our daily notes called medium-viewswith data that we get from the stats page of Medium.

Daily note metadata. Image by Nuno Campos

We could use the following code to generate the chart:

```dataviewjs
const rawData = await dv.query('TABLE file.name, full-date, Medium-Views FROM #daily-note WHERE Medium-Views SORT file.name');
const rows = rawData.value.values;
const chartData = {
  type: 'bar',
  data: {
    labels: rows.map(x => x[2]),
    datasets: [
      {label: 'Views', data: rows.map(x => x[3]), backgroundColor:     ['#C7F2A7']}         
    ],
  },
}
window.renderChart(chartData, this.container);
```
Medium Views. Image by Nuno Campos

Now you are ready to create charts in your Obsidian Vault using Obsidian Charts. Please read the documentation if you need more info.

Stay tuned for more Obsidian articles. Meanwhile, check out the previous parts of the My Obsidian Setup series.

Obsidian
Productivity
Notes
Notetaking
Programming
Recommended from ReadMedium