Skip to content

Support needed to create a dashboard. #28

@grostim

Description

@grostim

Hi !

I have discovered fava-dashboard a couple of weeks ago, and I love it. Thank you for this great addition to fava and beancount.

I am currently creating my own dashboards panels, and i have been able to reach pretty much all my expectations except for my last graph:

I want to create a stacked area graph showing the variation of my various assets over time.
My issue is that for some of the assets, i have some months without any returned balance as there is no transaction that month.
Trying to stack curve with missing points tends to brake the graph.
Is there a good way to fill the gaps in the dataset in order to get a proper result ?

Here is my (broken) graph and the corresponding code.

image

  - title: Actifs 📈 
    width: 100%
    link: /comptes-famille-gros/balance_sheet/
    queries:
    - bql: |
        SELECT year, month,
        CONVERT(LAST(balance), '{{ledger.ccy}}', DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS value
        WHERE account ~ '^Actif:Crypto'
        GROUP BY year, month
      name: Crypto
      link: /comptes-famille-gros/balance_sheet/?time={time}
      stack: detail
      areaStyle: {}
    - bql: |
        SELECT year, month,
        CONVERT(LAST(balance), '{{ledger.ccy}}', DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS value
        WHERE account ~ '^Actif:Bink'
        GROUP BY year, month
      name: PEA+CTO
      link: /comptes-famille-gros/balance_sheet/?time={time}
      stack: detail
      areaStyle: {}
    - bql: |
        SELECT year, month,
        CONVERT(LAST(balance), '{{ledger.ccy}}', DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS value
        WHERE account ~ '^Actif:(Boursorama:AVTim2|Boursorama:AVAnna1|Linxea)'
        GROUP BY year, month
      name: Assurances Vie
      link: /comptes-famille-gros/balance_sheet/?time={time}
      stack: detail
      areaStyle: {}
    - bql: |
        SELECT year, month,
        CONVERT(LAST(balance), '{{ledger.ccy}}', DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS value
        WHERE account ~ '^Actif:(Boursorama:CC|Boursorama:AVAnna2|Boursorama:LDD|Boursorama:CEL|Boursorama:LA|BanquePostale:LAAnna)'
        GROUP BY year, month
      name: Monétaire
      link: /comptes-famille-gros/balance_sheet/?time={time}
      stack: detail
      areaStyle: {}
    - bql: |
        SELECT year, month,
        CONVERT(SUM(position), '{{ledger.ccy}}') AS value
        WHERE account ~ '^Actif:Immobilier'
        GROUP BY year, month
      name: Immobilier
      link: /comptes-famille-gros/balance_sheet/?time={time}
      stack: detail
      areaStyle: {} 
    type: echarts
    script: |
      const currencyFormat = new Intl.NumberFormat(undefined, {
        style: "currency",
        currency: ledger.ccy,
        maximumFractionDigits: 0,
      });
      const months = helpers.iterateMonths(ledger.dateFirst, ledger.dateLast).map((m) => `${m.month}/${m.year}`);

      // the beancount query only returns months where there was at least one matching transaction, therefore we group by month
      const amounts = {};
      for (let query of panel.queries) {
        amounts[query.name] = {};
        for (let row of query.result) {
          amounts[query.name][`${row.month}/${row.year}`] = row.value[ledger.ccy];
        }
      }

      return {
        tooltip: {
          valueFormatter: currencyFormat.format,
        },
        legend: {
          top: "bottom",
        },
        xAxis: {
          data: months,
        },
        yAxis: {
          axisLabel: {
            formatter: currencyFormat.format,
          },
        },
        series: panel.queries.map((query) => ({
          type: "line",
          name: query.name,
          stack: query.stack,
          areaStyle: query.areaStyle,
          data: months.map((month) => amounts[query.name][month]),
          connectNulls: true,
        })),
        onClick: (event) => {
          const query = panel.queries.find((q) => q.name === event.seriesName);
          if (query) {
            const [month, year] = event.name.split("/");
            const link = query.link.replaceAll("#", "%23").replace("{time}", `${year}-${month.padStart(2, "0")}`);
            window.open(link);
          }
        },
      };

If this is not the right place to get support for your tool, let me know, and i will repost my message accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions