Problem creating chart with QuickChart node

Describe the problem/error/question

I use the n8n in queue mode with the following settings:
1 main
1 postgresql
1 redis
1 rabbitmq
2 workers
Nginx Proxy Manager (reverse proxy)

What is the error message (if any)?

I want to generate a graph from the data provided by a query in the postgres node.
In the example below, the postgres node returns four values: 79, 82, 98 and 96.
The problem is that the QuickChart node creates the charts but only with vertical data from 0 to 9.
I couldn’t find any option in the QuickChart node to fix this.
Where am I going wrong?

Share the output returned by the last node

  • n8n version: 1.31.2
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): queue
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu 22.04.4 (Jammy Jellyfish)

@sidney27 , both labels and data are expected to be arrays. I used Summarize node to produce arrays from the output of Postgres.

Is that what you are looking for?

1 Like

Good morning, @ihortom.
That’s exactly what I needed.
It worked out.

If you can help me more, is it possible for each bar to be a different color? (image below taken from the documentation)

Thank you very much, it helped a lot!

@sidney27 , for each bar to be of a different color, each number has to belong to a different dataset. That is instead of a single array you have to have 4 different and specific arrays. That is instead of

[  79,  82,  98,  96] ➔ color1

it should be something like

[79, 0, 0, 0] ➔ color1
[0, 82, 0, 0] ➔ color2
[0, 0, 98, 0] ➔ color3
[0, 0, 0, 96] ➔ color4

To achieve that, not only you would have to transform a single set of data into four sets with zeros as a “padding”, you would also have to utilize HTTP Request node instead of QuickChart and use a specific data structure as per QuickChart API, which will produce

Alternatively, you could have the 4 sets as below

[79] ➔ color1
[82] ➔ color2
[98] ➔ color3
[96] ➔ color4

which could be produced by

with outcome as

1 Like

I tried the example you provided, but the set node gives an error in the array.

Taking advantage, ihortomm, another need arose.
I will explain the purpose of the flow for better understanding.
I’m putting together a flow to create graphs using AI.
The idea is to ask chatgpt (using API) to create the postgres SQL query for a given query. This created query is executed by the postgres node and then follows the flow you already know.
The issue is that the data will not always be the same, nor the quantity, as in the example we are using (number of calls per department).
How do I make the creation dynamic according to the amount of data generated?
Below is an example of another query.
Thank you very much in advance for the time you invested in helping me.

You seemed to have missed that count is expected to be turned into an array. You have to use the expression like this, {{ [$json.count] }} instead of just {{ $json.count }}.

You seem to be introducing yet another dimension that needs to be taken into account, namely mes (month). That would require some adjustments reflected in the workflow below.

The outcome is

This, however, assumes that you have data produced for each month and area. For this to work, you need to make sure SQL returns 0 for the areas in that month when there is no data for it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.