My customer would like to build a chart report dynamically. He would like to decide which and how many historical tags will be plotted on the report just at the report print out time.
I managed to use input report parameters to dynamically change the Selected Historical Tags paths just like in the following screenshot
where parameter {itemNr} will cause the report to plot the speed and the current of up to 10 different motors, depending on selections made by the operator at runtime.
But I cannot figure out how to define the Selected Historical Tags just as if they were a dataset I can inject into the report from the outside (that could by the way I can change not only the single tag paths, but also the amount of tags being plotted).
Is there any solution? Maybe by mean of the Script datasource?
You would have to use the script datasource to query history dynamically. However, youâll then run into the next problem - you wonât be able to configure the number of pens on the final chart dataset. Youâll need to run another script in configureChart to pull in the actual historical data and put it onto your chart (or, predefine a fixed number of pens, and then hide them in configureChart if they have no data). Neither is trivial.
As I can see in the Edit Script pain the chart component is JFreeChart. I don't know that component in details, so I've printed out all component members with a print dir(chart) from inside the configurChart script. Unfortunately I cannot find any members that resembles anything like setData or alike. Do you have any suggestion or shall I study the JFreeChart javadoc?
Youâll have to get pretty comfortable with JFreeChart, unfortunately. Hereâs an example project I made that uses the second method - a fixed number of pens are statically configured on the chart, then the script removes pens with no data. This is the less ideal fix, but the only one possible in earlier versions of Ignition - prior to 7.9.7, scripts in reporting didnât have access to chart datasources.
Hallo PGriffith, many thanks for the example you provided. Iâm just trying out your project but I cannot figure out how you are passing the history data you queried in the script datasource to the chart component: inside configureChartdata[âhistoryâ] is never mentioned.
Thanks, regards
UPDATE
Hallo PGriffith, I managed to have your project working. I saw that the link between our data and the data being plotted onto the chart is the Data Key property
and that the Pens Tang Key are fixed, i.e. I must use those key in my chart pens configuration dataset.
I managed also to change the pen name that is shown to the operatore
by adding a âTagDescriptionâ column to my configuration dataset.
Is there a way to do with but use a Tag Browse tree to pick the tags. Maybe a Easy Chart to drop the tag on, and Date Range to pick when the report is gets the data. I was going to use vision to do this. So that I can add it to new projects and give the operator a way to dynamic make a report with whatever tags and whatever time range.
See @PGriffithâs responses. Use a script data source. Customize the JFreeChart to manually generate your desired pens from the scripted data. To pass the pen list, I would construct a dictionary in Vision with the details, and serialize as json to a string parameter of the report. The script data source would deserialize that and perform the necessary history queries.
I got your example to work, but you are currently not using a âproperâ time axis.
I want to include my time axis in the plot, is that possible?
I have added the t_stamp column as a list, xlist = [sData.getValueAt(i,0) for i in range(sData.getRowCount())]
to your code, why is this not working? (it has the correct length)
########################################################
#builds a new dataset, removes null pens:
from org.jfree.data.xy import DefaultXYDataset
plot = chart.getPlot()
renderer = plot.getRenderer()
legenditems = plot.getLegendItems()
dataset = plot.getDataset()
newds = DefaultXYDataset()
sData = data['mykey']
xlist = [sData.getValueAt(i,0) for i in range(sData.getRowCount())]
#xlist = range(dataset.getItemCount(0))
for col in range(dataset.getSeriesCount()):
ylist = []
for row in range(dataset.getItemCount(col)):
ylist.append(dataset.getY(col, row))
try:
sum(ylist)
newds.addSeries(legenditems.get(col).getLabel(), [xlist, ylist])
except TypeError:
del ylist
plot.setDataset(0, newds)
I honestly donât know - itâs been so long since I made that example (and it was hacky to begin with). I would recommend going with the other approach I mentioned if youâre on a modern version of Ignition - itâs going to be easier to maintain.
I donât understand what youâre trying to do.
I canât think of a scenario where you would need to change a parameterâs value inside the report body. Parameters are just that - implicitly fixed input values to your report. Your reportâs datasources should change as needed based on those input values.
Thank you, firstly I think that Table component could accept to change a parameterâs value inside itselves to apply Grouping data. Now I have another solution. I create new datasource to solve my issue that grouping by my dynamic keys.