# Bar chart scripts in the report

**URL:** <https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877>\
**Category:** Ignition\
**Created:** [March 31, 2022, 2:52pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877 "2022-03-31T14:52:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jefferson\_Nascimento](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jefferson\_Nascimento](https://forum.inductiveautomation.com/u/Jefferson_Nascimento)\
**Post date:** [March 31, 2022, 2:52pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/1 "2022-03-31T14:52:50Z")

</div>

How can I manually enter the data into the bar chart by script in a report?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/53fdf10a90bfaacae5d1d94ea11a1e1940c62e95.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 31, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/2 "2022-03-31T15:09:51Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/6753f0687245e083d334e18d2064912663c6aa81.png)

In the `Data` tab of the report editor, create a new **script** data source. Then write your script inside the `updateData()` function and assign the resulting dataset to a key, ie

```auto
data['MyBarChartData'] = system.dataset.toDataSet(myHeader,myData)

```

You can then assign the `MyBarChartData` key, or whatever you want to name it, to the bar chart component.

---

<div class="post-metadata">

**Author:** ![Jefferson\_Nascimento](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jefferson\_Nascimento](https://forum.inductiveautomation.com/u/Jefferson_Nascimento)\
**Post date:** [March 31, 2022, 7:58pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/3 "2022-03-31T19:58:52Z")

</div>

> [@dkhayes117](#):
>
> `data['MyBarChartData'] = system.dataset.toDataSet(myHeader,myData)`

How could I distribute these values in this script?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/9/e955f95fc2078b2d240944df57ee92530600d286.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 31, 2022, 8:00pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/4 "2022-03-31T20:00:48Z")

</div>

> [@Jefferson\_Nascimento](#):
>
> How could I distribute these values in this script?

Could you be more specific? I'm not sure what you are asking.

---

<div class="post-metadata">

**Author:** ![Jefferson\_Nascimento](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jefferson\_Nascimento](https://forum.inductiveautomation.com/u/Jefferson_Nascimento)\
**Post date:** [March 31, 2022, 8:21pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/5 "2022-03-31T20:21:00Z")

</div>

> [@Jefferson\_Nascimento](#):
>
> How could I distribute these values in this script?

In the image above I made a relationship between days of the month and flow. I would like to "assemble" this table through the report script.

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [March 31, 2022, 8:21pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/6 "2022-03-31T20:21:14Z")

</div>

Hi Jeferson, if what you want is an example script on how to build the dataset you’re showing, here:

```auto
#To make a dataset, you'll need a list of headers and a list with your data
#The headers list is simple:
myHeader = ['Day','Flow']

#Now, the data list is a list of lists that needs to be the same lenght of the list of headers,
#So if you have 2 headers, your data list will must have 2 itens per row
#You can add more rows by adding more lists itens inside your data list.
data = [[1,100],
	    [2,150],
	    [3,140],
	    [4,160],
	    [5,110],
	    [6,115],
	    [7,140],
	    [8,110],
	    [9,150],]
#Not that we have both, you just need to use the "system.dataset.toDataSet" to create your dataset
#and then use it in the report, or any place that uses datasets, actually.
#And here's the code dkhayes117 provided:
data['MyBarChartData'] = system.dataset.toDataSet(myHeader,data)

```

---

<div class="post-metadata">

**Author:** ![Jefferson\_Nascimento](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jefferson\_Nascimento](https://forum.inductiveautomation.com/u/Jefferson_Nascimento)\
**Post date:** [March 31, 2022, 8:59pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/7 "2022-03-31T20:59:33Z")

</div>

Thanks, Leonardo!!!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 31, 2022, 9:06pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/8 "2022-03-31T21:06:11Z")

</div>

It is bad practice to assign the list of raw data to the variable `data` because that is the default dictionary for the data sources.

> [@leonardo.godoi](#):
>
> `data = [[1,100],`

This will override any data that was previously in the `data` dictionary wiping out any query source data or parameters. Always name it something like `scriptData` instead.

```auto
#To make a dataset, you'll need a list of headers and a list with your data
#The headers list is simple:
myHeader = ['Day','Flow']

#Now, the data list is a list of lists that needs to be the same lenght of the list of headers,
#So if you have 2 headers, your data list will must have 2 itens per row
#You can add more rows by adding more lists itens inside your data list.
scriptedData = [[1,100],
	    [2,150],
	    [3,140],
	    [4,160],
	    [5,110],
	    [6,115],
	    [7,140],
	    [8,110],
	    [9,150],]
#Not that we have both, you just need to use the "system.dataset.toDataSet" to create your dataset
#and then use it in the report, or any place that uses datasets, actually.
#And here's the code dkhayes117 provided:
data['MyBarChartData'] = system.dataset.toDataSet(myHeader,scriptedData)

```

I've been burned with this a couple of times myself.

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [April 1, 2022, 12:45pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/9 "2022-04-01T12:45:31Z")

</div>

Oops, forgot to change that, it’s a good reminder,it’s really annoying making this mistake and finding it

---

<div class="post-metadata">

**Author:** ![Jefferson\_Nascimento](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jefferson\_Nascimento](https://forum.inductiveautomation.com/u/Jefferson_Nascimento)\
**Post date:** [April 1, 2022, 1:55pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/10 "2022-04-01T13:55:19Z")

</div>

Taking advantage of the topic, in addition to inserting manual values in this script, is it possible to insert values from other queries?  
I need to put in the bar chart day x flow, where the days will be entered manually and the flow will be done by queries by historical tags and SQL queries

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 1, 2022, 2:17pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/11 "2022-04-01T14:17:34Z")

</div>

You can get parameters into your scripting source by using the parameter name as a key…

```auto
dateParameter = data['date']

```

You can get query results like so

```auto
queryDS = data['myQuery'].getCoreResults()

```

---

<div class="post-metadata">

**Author:** ![Jefferson\_Nascimento](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jefferson\_Nascimento](https://forum.inductiveautomation.com/u/Jefferson_Nascimento)\
**Post date:** [April 1, 2022, 5:48pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/12 "2022-04-01T17:48:33Z")

</div>

That way it returns column and row. How to return only the value?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 1, 2022, 6:10pm UTC](https://forum.inductiveautomation.com/t/bar-chart-scripts-in-the-report/57877/13 "2022-04-01T18:10:19Z")

</div>

If I understand you correctly, to get a single value from a query (scalar value) you have a couple of options. You could run [system.db.runScalarPrepQuery()](https://docs.inductiveautomation.com/display/DOC81/system.db.runScalarPrepQuery) inside the script source, or extract the value you want from the query dataset.

```auto
ds = data['myQuery'].getCoreResults()
value = ds.getValueAt(0,0)

or 

ds = data['myQuery'].getCoreResults()
pyDS = system.dataset.toPyDataSet(ds) # This makes the ds iterable
value = pyDS[0][0] # access value by indexing
for row in pyDS: # or iterate over the dataset 
    for value in row:
        print value

```
