# Populate XY chart

**URL:** <https://forum.inductiveautomation.com/t/populate-xy-chart/94337>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 8, 2024, 12:14pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337 "2024-08-08T12:14:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [August 8, 2024, 12:14pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/1 "2024-08-08T12:14:47Z")

</div>

Hello!

I´m trying to populate a XY chart from a named query,

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/01e41179aaff5fde73322bb85dd763a130a4d3a3.png)

I binded the props.dataSources.example to my named query.

The original named query has 4 columns, in order to populate the chart I leave it like 2 with a script transform:

```python
	# Get the dataset from the named query result
	data = system.dataset.toPyDataSet(value)
	
	# Initialize lists to hold the transformed data
	descriptions = []
	peticiones = []
	
	# Iterate through the dataset and extract the needed columns
	for row in data:
	    descriptions.append(row['DESCRIPCION'])
	    peticiones.append(row['NUMERO PETICIONES'])
	
	# Create a new dataset in the desired format for an XY Chart
	headers = ['X', 'Y']
	new_data = []
	
	# Populate the new dataset with the transformed data
	for i in range(len(descriptions)):
	    new_data.append([peticiones[i], descriptions[i]])
	
	# Convert the list to a PyDataSet
	new_dataset = system.dataset.toDataSet(headers, new_data)
	
	# Return the new dataset
	return new_dataset

```

....but....nothing showing on the chart.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/2/6224758a61e3ae01484ef37e4f96b37f13fa91f9.png)

Any ideas on how to fix this are welcome.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 8, 2024, 12:20pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/2 "2024-08-08T12:20:25Z")

</div>

Show us the returned dataset. (You can copy to clipboard and paste with \</\> in post).  
 ![Returned dataset](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/b/4b38339c25e9f37382cbf48b760f52df6e65986d.png)

Post the JSON for the XY Chart as well so we can reproduce it.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [August 8, 2024, 12:38pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/3 "2024-08-08T12:38:47Z")

</div>

here is it

```python
"#NAMES"
"X","Y"
"#TYPES"
"D","str"
"#ROWS","15"
"1.0","CON_REVTAB - CON Revision tablet/sensores"
"1.0","COR_COLMOB - COR Colocacion mobiliario edificios"
"1.0","COR_TRAMAT - COR Traslado Material"
"1.0","COR_REVTAB - COR Revision tablet/sensores"
"1.0","COLMOB - Colocacion mobiliario edificios"
"4.0","CON_SUMMOB - CON Suministro mobiliario"
"2.0","COR_TRAMAT - COR Traslado Material"
"1.0","COR_MONMOB - COR Montaje mobiliario"
"1.0","COR_MONALM - COR Montaje Almacen"
"1.0","CON_ASTRAS - CON Asistencia a Traslado"
"1.0","CON_DESMOB - CON Desmontaje mobiliario"
"1.0","COR_DESALM - COR Desmontaje Almacen"
"1.0","CON_ADVMA - CON Tareas admvas. y de soporte"
"1.0","COR_REVTAB - COR Revision tablet/sensores"
"3.0","COR_MONSAL - COR Montaje de Salas"

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 8, 2024, 12:58pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/4 "2024-08-08T12:58:02Z")

</div>

> [@Alejandro\_Alaco](#):
>
> ```python
> for i in range(len(descriptions)):
> new_data.append([peticiones[i], descriptions[i]])
> 
> ```

If you are trying to make a bar chart then you will have categories on the X-axis so, I think, they should come first, like this:

```python
	for i in range(len(descriptions)):
	    new_data.append(descriptions[i]], [peticiones[i])

```

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [August 9, 2024, 11:56am UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/5 "2024-08-09T11:56:00Z")

</div>

I didn´t add the name of the headers in the data.x and data.y

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

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

but still have an issue:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/20d7b58b8bc587abc8b9d17f31f3c88632b3ddc4.png)

wich is because having too much data from the named query

> [@\[XY Chart\] Maximum call stack size exceeded](https://forum.inductiveautomation.com/t/xy-chart-maximum-call-stack-size-exceeded/75696):
>
> Hi, On an XY Chart, I've got : an error saying "Maximum call stack size exceeded" : no line appearing on the chart Below is the summary code for my chart. And the source dataset : [dataset\_moy\_cintre\_t\_stamp.txt](https://forum.inductiveautomation.com/uploads/short-url/uzTru5MIa4m0BGMEKYVwxmNw9De.txt) (17.5 KB) Thanks in advance for any advice. [maximum call stack size exceeded] 
> 
> > **Summary**
> >
> > [ { "type": "ia.chart.xy", "version": 0, "props": { "legend": { "position": "top" }, "xAxes": [ { "n…

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 9, 2024, 12:36pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/6 "2024-08-09T12:36:18Z")

</div>

I can’t speak to your call stack size issue. 15 data points shouldn’t be too much for the chart.

However, your script is far too complex for what you’re doing.

This is all you need:

```python
return system.dataset.filterColumns(value,['NUMERO PETICIONES', 'DESCRIPCION'])

```

Then just use those column names in your props to indicate which column should be X and which should be Y.

Better would be to use an expression transform with the `columnRearrange` function which can be used to both filter and rearrange the columns.

Best would be to not bind directly to the data source with the named query but to bind that to a custom property to hold the raw dataset and then use an expression binding on the data source to filter the columns.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [August 9, 2024, 12:55pm UTC](https://forum.inductiveautomation.com/t/populate-xy-chart/94337/7 "2024-08-09T12:55:49Z")

</div>

Thanks Irose,

I´m already able to see the "NUMERO PETICIONES" on the XY chart, but not the "DESCRIPTION", maybe too long text..

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

will check on the query to see why this is happening.
