Creating a smart chart

hey! I am trying to create an ismart chart but the truth is that I am not achieving my goal, I have read the documentation on the subject but I do not think it is enough.

In my project I have a schema called Transactions which has the following form:

As you can see, it has a related field which contains charity_id and amount to pay to that charity.

What I would like to achieve is to create a chart where you can see the charity_id and the sum of all the amounts corresponding to different transactions but to the same charity id.

For example if I have transcction1->charity1->amount=30 and transcction2->charity1->amount=70, I could see in the dashboard a graph that would be:
| charityid | amount |
1. 100

I suppose that creating a chart where the datasource is a query could be achieved but the issue is that I do not see this option when I want to create charts, only simple and api appears.

I appreciate your help,
Thank you!

Hi @usr1vang :wave: you can take a look at this documentation

After that, you can call a specific endpoint on your api with this.lianaServerFetch.fetch('/forest/your-endpoint', {});.

You must define this endpoint in your server and code your logic inside, to return a list containing [{ charityId: 1, amount: 100 }].

let me know if you want some help in a specific point.

1 Like

Hi, thanks for your answer. Could you please provide me with some example code of a endpoint in api to visualize on the chart?
I not sure how to do it.
Thanks!

I don’t know, you declare an route inside a route file like this

router.get('/your-endpoint', (req, res) => {
  res.send([{ charityId: 1, amount: 100 }]);
});

a thing something like that :slight_smile:
After that you can use the response to create your own chart.

1 Like