Example request - Update Props.dataSources via script

Please help me with an example using a script to call a namedquery, and parse that data into new dataset with additional logic.

I am struggling with understanding how to update an XY Chart’s Props datasource with the new dataset via script.

Maybe with onload event.

Best place to get started is to head over to IA university, there is a shortcut at the top of the page. Go over Ignition Scripting videos to get your feet wet. Once you watch those, come back with your first attempt with any questions.

The user manual is very helpful as well, also linked at the top of the page.

Scripting Functions

Not a single example of this in all the IU classes. do you know a good way to do what was mentioned in OP?

Give us something to work with. Attach a script where you've at least tried to call a named query, and we can go from there.

The named query is not the issue. I need the dataset to be pushed into the datasource:

This must be simple…. I am just missing something small I am sure.

Use the XY Chart Gantt example dictionary as the dataset…. how to I update the datasouce with a script?

[
{
"name": "John",
"fromDate": "2018-01-01 08:00",
"toDate": "2018-01-01 10:00",
"color": "#00FF30"
},
{
"name": "John",
"fromDate": "2018-01-01 12:00",
"toDate": "2018-01-01 15:00",
"color": "#FF0030"
},
{
"name": "John",
"fromDate": "2018-01-01 15:30",
"toDate": "2018-01-01 21:30",
"color": "#00FF30"
},
{
"name": "Jane",
"fromDate": "2018-01-01 09:00",
"toDate": "2018-01-01 12:00",
"color": "#00FF30"
},
{
"name": "Jane",
"fromDate": "2018-01-01 13:00",
"toDate": "2018-01-01 17:00",
"color": "#FF0030"
},
{
"name": "Peter",
"fromDate": "2018-01-01 11:00",
"toDate": "2018-01-01 16:00",
"color": "#00FF30"
},
{
"name": "Peter",
"fromDate": "2018-01-01 16:00",
"toDate": "2018-01-01 19:00",
"color": "#00FF30"
}
]

Let's start with getting the named query data into the property. The best way to do this is with a named query binding. Beside the data property, there will be a little chain link icon that when clicked on, will allow to choose between different binding types. Click on the query one, and put in your path and parameters.

EDIT: Do not put the binding on the dataSources prop but on one of the values under it, IE schedule_data.

1 Like

forget the namedquery part… lets just go from dataset or pydataset to chart props datasource. That is the missing part. How to I update the Chart properties(datasource specifically) from a script. Thanks.

The easiest way, but has a little more overhead than others, is to bind the named query to the specific data source, then in that binding, add a transform. It is a button that is visible in the same popup where you configure the binding.

Use a script transform on the binding to manipulate the data as needed. Anytime the NQ binding updates, the transform will subsequently run.

For best performance, I use Phil's Integration Toolkit (3rd party module) that enables data looping in expressions along with other features. This dodges the scripting interpreter overhead.

1 Like