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
546 stars 25 forks source link

Any chance this could be made to work together with formulas used by Advanced Tables? #117

Open n00bmind opened 4 months ago

n00bmind commented 4 months ago

Describe the feature

Hi. I'm currently using the Advanced Tables plugin to add a simple "totals" column to my tables, which is super useful. However, as described in https://github.com/tgrosinger/advanced-tables-obsidian/blob/main/docs/help.md, the way this works is by adding one (or more) html comment line of the form <!-- TBLFM: [formula] --> directly after the table, which is currently incompatible with the "chart from table" feature, as I cannot have both the formula and the required the block id marker as the next line after the table.

i.e. I'd need to be able to do something like this:

|       | Test1 | Test2 | Test3 |
| ----- | ----- | ----- | ----- |
| Data1 | 1     | 2     | 3.33  |
| Data2 | 3     | 2     | 1     |
| Data3 | 6.7   | 4     | 2     |
| TOTAL |       |       |       |
<!-- TBLFM: @>$2=sum(@I..@-1) -->
^table

but if I try something like this I get the error "Couldn't render Chart: There is no table at that id and/or file"

Does this fix a problem? If so, specify.

It does. This would make Charts work with computed formulas, which adds a lot of power to a user's workflow!

Did you consider other alternatives?

I don't know any other alternatives at the moment..

Screenshots and recordings

No response

thiduzz commented 4 months ago

Going through the same drama as well 🤣

Kolossi commented 3 weeks ago

@n00bmind @thiduzz I came here to +1 this, but I've actually just found a workaround :-)

The block id marker doesn't have to be following the table, it can be within it, so try changing your example table to:

| ^table | Test1 | Test2 | Test3 |
| ----- | ----- | ----- | ----- |
| Data1 | 1     | 2     | 3.33  |
| Data2 | 3     | 2     | 1     |
| Data3 | 6.7   | 4     | 2     |
| TOTAL |       |       |       |
<!-- TBLFM: @>$2=sum(@I..@-1) -->

If there was text in the first cell it could also be e.g.:

| Data ^table | Test1 | Test2 | Test3 |
| ----- | ----- | ----- | ----- |
| Data1 | 1     | 2     | 3.33  |
| Data2 | 3     | 2     | 1     |
| Data3 | 6.7   | 4     | 2     |
| TOTAL |       |       |       |
<!-- TBLFM: @>$2=sum(@I..@-1) -->

or put the block id in any other empty cell.

Seems to work in a similar example for me (desktop obsidian v1.6.5)

n00bmind commented 3 weeks ago

Amazing stuff. That seems to work for me just fine too..

thiduzz commented 3 weeks ago

Good stuff @Kolossi ! Works for me as well!