I´m trying to populate a XY chart from a named query,
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
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.