phibr0 / obsidian-charts

Charts - Obsidian Plugin | Create editable, interactive and animated Charts in Obsidian via Chart.js
https://charts.phib.ro/
GNU Affero General Public License v3.0
610 stars 28 forks source link

[Bug]: annotations don't work with chart-from-table #113

Open SonjaBlack opened 9 months ago

SonjaBlack commented 9 months ago

Describe the bug

First, thanks for this plugin. The chart-from-table capability is wonderful.

However, I would like to be able to add annotations to my charts. With charts generated from dataviewjs, this works. But with chart-from-table, I cannot get it to work at all.

Relevant errors (if available)

No response

Steps to reproduce

I found an working example online of adding annotations in the JSON object passed to window.renderChart():

options: { plugins: { annotation: { annotations: { myAnnotation: { type: 'box', yMin: 100, yMax: 300, backgroundColor: 'rgba(255,99,132,0.15)' } } } } }

Based on how the other elements of that JSON map to the YAML in a chart code block, it looks like this should work:

type: line
id: myTable
file: "My Table"
layout: columns
beginAtZero: true
options:
  plugins:
    annotation:
      annotations:
        myAnnotation:
          type: box,
          yMin: 100,
          yMax: 300,
          backgroundColor: 'rgba(255,99,132,0.15)'

But it does not. The chart renders correctly, but there is no annotation. I have tried removing different levels of that options block (i.e. starting with plugins instead of options, and all the way down), but with the same results every time: a perfect chart, but with no annotations.

Expected Behavior

The charts plugin should pass any given options along to their indicated plugins. This doesn't seem to be happening.

As an enhancement to that, it would be nice if we didn't have to include the options/plugins/annotation levels in the YAML as well; they don't really add anything. The charts plugin should know which chartjs plugins it is using and should recognize a top-level YAML key for each one's options.

Additional context

I did try solving this on my own first. I have read ALL the documentation for the charts plugin, many blogs and other user-generated content about using charts, have asked in the obsidian forums and subreddit, but have not been able to find a way to make annotations work with chart-from-table.

Code

No response

Operating system

Windows