Report Module: Tag Historian Query dynamic tags list

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
immagine
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?

Thanks in advance

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.

Oh, I understand. Many thanks PGriffith, I will think about your suggestion.
Regards

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?

1 Like

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.

Dynamic Tag History.proj (13.5 KB)

1 Like

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 configureChart data[‘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
image
and that the Pens Tang Key are fixed, i.e. I must use those key in my chart pens configuration dataset.
image
I managed also to change the pen name that is shown to the operatore
image
by adding a “TagDescription” column to my configuration dataset.

1 Like

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.

Something like this:

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.

Doable, but decidely non-trivial.

1 Like

This looks great,
so to confirm:

  • The dataset have three columns (Range Key, Tag Path, TagDescription).
  • The pens Range Keys in the report chart should be statically inserted.

Hi @PGriffith,

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.

Hmm. Programming inside the chart is not trivial. My mind hurts :hot_face: Im so close, just missing that t_stamp, on the x-axis…

Anyone knows how to populate the reporting chart with just a simple dynamic pen (including the t_stamp column from the normal tag historian)

Thank pmgo & PGriffith, so Is there any solution to update ‘parameter reporting’ in table detail component with Key data?

SiteName image
image

Can i update SiteName parameter?
image

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.