Possible to Pick and Choose X/Y data for chart from dataset?

Is it possible to pick and choose the x and y data sources for a chart from a dataset that is already retrieved without creating a new sql query or stored procedure that formats the returned data in the correct order to be displayed in a chart?

I have a stored procedure that returns a large dataset every few minutes, from which I want to make about 8 different charts from.

Thoughts?

Thanks,
Casey


You can create datasets out of a single dataset in scripting. For example, do the following:

  1. Add a custom property to the root container of the window called “origData” that is a dataset.

  2. Bind it to the stored procedure you talked about that returns the large dataset.

  3. When the property changes we can run code that can create new datasets. So add a propertyChange event to the root container like this:[code]if event.propertyName == “origData”:
    origData = system.dataset.toPyDataSet(event.newValue)
    newData1 = []
    newData2 = []
    newData3 = []

    for row in origData:
    newData1.append([row[0], row[1], row[2]])
    newData2.append([row[3], row[4], row[5]])
    newData2.append([row[6], row[7], row[8]])

    event.source.parent.getComponent(“Chart 1”).Data = system.dataset.toDataSet([“Col Name 1”, “Col Name 2”, “Col Name 3”], newData1)
    event.source.parent.getComponent(“Chart 2”).Data = system.dataset.toDataSet([“Col Name 1”, “Col Name 2”, “Col Name 3”], newData2)
    event.source.parent.getComponent(“Chart 3”).Data = system.dataset.toDataSet([“Col Name 1”, “Col Name 2”, “Col Name 3”], newData3)[/code]Here I just made three separate datasets with different columns. You can pick and choose what you want. Once I make them I can set them on any component, like a graph.

Enjoy!

Awesome! That really helps!

Thanks

Travis,

I have come up with an error when attempting to run the script. Any thoughts as to what I may have to change? Is it expecting an integer?

Thanks
Casey Swett


Error executing script for event property change on component: Root Container

Traceback (most recent call last):

File “event:propertyChange”, line 12, in

TypeError: getComponent(): 1st arg can’t be coerced to int

Ignition v7.4.2 (b953)
Java: Sun Microsystems Inc. 1.6.0_31

Line 12 being: event.source.parent.getComponent(“Chart 1”).Data = system.dataset.toDataSet([“Col Name 1”, “Col Name 2”, “Col Name 3”], newData1)

I did some more experimenting last night “learning”. I tried adding another custom property to the Root Container of the window named newData1 which already has origData. I also tried adding the Charts such as Chart 1, Chart 2, Chart 3.

I still end up with the error:

File “event:propertyChange”, line 12, in

TypeError: getComponent(): 1st arg can’t be coerced to int

For example, All columns with numbers such as METRICID, GOAL, and PREYEAR are all doubles if that makes a difference.

I trying to get a better understanding of how the rows and columns from within the script.

Thanks
Casey








Unless you’re in category mode, the Classic Chart requires the first column in that new data set to be a timestamp. I can’t see if your master dataset has any timestamps you can use but I’d start there.

Well, if your datasets exists on the root container called newData1, newData2, etc… you should have something like:event.source.newData1 = system.dataset.toDataSet(....)My code was trying to set datasets on the chart itself. It requires the name of your chart to be “Chart 1”.

Alright, thanks for the help. I was able to get data into the datasets now, so I believe I can make it display in a chart now once I pick the correct columns.

Thanks
Casey