Populate XY chart

Hello!

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

image

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:

	# 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

Any ideas on how to fix this are welcome.

Show us the returned dataset. (You can copy to clipboard and paste with </> in post).
Returned dataset

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

here is it

"#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"

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:

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

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

image

image

but still have an issue:
image

wich is because having too much data from the named query

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:

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.

4 Likes

Thanks Irose,

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

image

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