# SqlLite and BarGraph

**URL:** <https://discourse.nodered.org/t/sqllite-and-bargraph/78491>\
**Category:** General\
**Created:** [17 May 2023 12:42 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491 "2023-05-17T12:42:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spectre68](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Spectre68](https://discourse.nodered.org/u/Spectre68)\
**Post date:** [17 May 2023 12:42 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/1 "2023-05-17T12:42:28Z")

</div>

Hi, I'm new to this forum. I have also been using node red for some time now, I'm trying to display the consumption and production values ​​(by month) in a bar graph. Selected data from a SqlLite DB. I can extract and correctly display data on two separate graphs. I've tried to combine them into one graph but I can't display the data correctly. is help possible?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 May 2023 13:58 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/2 "2023-05-17T13:58:28Z")

</div>

What are you using to create the graphs?  
What version of NR and node.js?  
What version of the dashboard?

Please provide a sample flow (with hard coded data) that displays the problem you are having.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [17 May 2023 14:23 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/3 "2023-05-17T14:23:50Z")

</div>

pls share the data as requested by @zenofmud.  
you can review the thread discussed here to start with, there are few example codes in there also.

> [@Ui\_chart alternate (Apex chart ?) Just want the zoom feature in the graph](https://discourse.nodered.org/t/ui-chart-alternate-apex-chart-just-want-the-zoom-feature-in-the-graph/76888):
>
> I have a ui\_chart node in the dashboard, which is working fine. the data is fed from a mysql query , processed and is displayed as expected. attaching a sample data and flow here i want to have zoom feature and i tried many things, most of the suggestions were to use apex chart. unfortunately i could not find any working example of how to get a apex chart from a template node and feed my example data into it. any help is appreciated. [{"id":"84007d4dbb2b8f8f","type":"change","z":"cdf172901326…

---

<div class="post-metadata">

**Author:** ![Spectre68](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Spectre68](https://discourse.nodered.org/u/Spectre68)\
**Post date:** [17 May 2023 14:50 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/4 "2023-05-17T14:50:30Z")

</div>

Sorry, I had entered the data but not requested but they have not been saved in the forum.  
version 3.0.2 with the default dashboard.

The first is SQL which I use to pull data from the DB. The second is in a function node that I use to create the bar graph. this is just to view the production every single day,  
I would also like to insert consumption data in the same bar graph (for a single day).

 ![2023-05-17 16_55_48-Node-RED _ 192.168.0.100](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/536c4138ae88b739d362ee5a777ebaa100a1bd64.png)

```auto
if (monthnumber==0){
    msg.topic = "select day,month, max(kwh_p), max(kwh_c) from ENERGIA_C GROUP BY (day)"
    msg.mytest = "Tutto"
}else {
    msg.topic = "select day,month, max(kwh_p), max(kwh_c) from ENERGIA_C WHERE month=" + monthnumber + " GROUP BY (day)"
    msg.mytest = monthnumber
}

```

```auto
var data_out = [];
var data_out1 = [];
var data_out2 = [];
var consumokw
var produzionekw
var a1 = [];
var a2 = [];
var a3 = [];
var temp1=[];
var temp2 = [];
var temp3 = [];
var kp="Kw/h+";
var kc = "Kw/h-";

for (var i = 0; i < msg.payload.length; i++) {
    var dt = msg.payload[i].day;   
    produzionekw = parseInt(msg.payload[i]["max(kwh_p)"]);
    //consumokw = parseInt(msg.payload[i]["max(kwh_c)"]);
    temp1 =[dt];   
    temp2 = produzionekw;  
    temp3 = [kp]; 
    a1.push(temp1);
    a2.push(temp2);
    a3.push(temp3);
  
}
temp1.concat
temp2.concat
temp3.concat

data_out=a1;
data_out1 = [a2];
data_out2 = a3;

msg.payload=[{
    "series": data_out2,  
    "data": data_out1,
    "labels": data_out
}];

return msg;

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 May 2023 15:29 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/5 "2023-05-17T15:29:22Z")

</div>

Add a `file-out` node to the output of one of the DB nodes and create a file.

Now you should be able to use an `inject` node connected to the `file-in` and send the output to the two `function` nodes to create a test case showing the current results.

That is the best way to get quick help from any of us that are volunteering to help you.

---

<div class="post-metadata">

**Author:** ![Spectre68](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Spectre68](https://discourse.nodered.org/u/Spectre68)\
**Post date:** [19 May 2023 08:14 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/6 "2023-05-19T08:14:24Z")

</div>

I'll do some testing, thanks.

---

<div class="post-metadata">

**Author:** ![Spectre68](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Spectre68](https://discourse.nodered.org/u/Spectre68)\
**Post date:** [19 May 2023 14:15 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/7 "2023-05-19T14:15:28Z")

</div>

Sorry...

can two arrays (such as a1 and a2 ) be merged together into one array which should result in a3?

```auto
array a1 [1,2,3,4,5,6,7,8,9,10,11,12]
array a2 [10,20,30,40,50,60,70,80,90,100,110,120] 

array 3 [[1,2,3,4,5,6,7,8,9,10,11,12], [10,20,30,40,50,60,70,80,90,100,110,120] ],

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 May 2023 21:06 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/8 "2023-05-19T21:06:42Z")

</div>

I think this will work:  
Array3 = [a1,a2]

---

<div class="post-metadata">

**Author:** ![Spectre68](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Spectre68](https://discourse.nodered.org/u/Spectre68)\
**Post date:** [20 May 2023 15:03 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/9 "2023-05-20T15:03:45Z")

</div>

Perfect, thank you very much

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 July 2023 15:03 UTC](https://discourse.nodered.org/t/sqllite-and-bargraph/78491/10 "2023-07-19T15:03:58Z")

</div>

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