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.
You can create datasets out of a single dataset in scripting. For example, do the following:
Add a custom property to the root container of the window called “origData” that is a dataset.
Bind it to the stored procedure you talked about that returns the large dataset.
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.
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.
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.