Average value of a pen on an easy chart

I know there has to be an easy way to do this,

All I want to do is bind the average value of a specific pen in my easy chart to a label or numeric label.

I know I can use a calculated pen and mouse over it but I want to get the average value as a value for use in a calculation elsewhere in the page to indicate a cost.

Any hints?

I know how to get the window size etc but I am unsure how to do it.

inserting a table onto my page I can configure a single historical tag and use an aggregate function - average with the easychart start and stop times as the period to evaluate but is there any direct way to do it from the chart to a label? The problem with a table is that even if I restrict the returns to 1, it still gives me a seperate row per day and if I select 4 days as the window in my easy chart, I want an average over the 4 days returned.

I have been searching for a way to do this as well. Average by certain rules… average of combined pins by other variable metrics like per minute.

I was also hoping to have the charts change colors if levels were rising or falling at too fast or slow of a given rate.

My best option is having to create a view in the database and charting that, annoying problem is the historian is broken into multiple tables for date ranges… it is getting complicated having to decode all the sub tables and their relations only to get what you would think would be a common charting feature… comparisons, trends and averages are what the suits want to see. Projections would be nice as well.

I am new to this so if there is a way that I am unaware of please point me to the documentation and an example if available.

Yeah I think the key to making it easy to work with data from split/partitioned tables is to let ignition do the work. I like the tag history binding available in tables, it makes it really easy to do simple things with historical data.

Now I just have to work out if I can somehow achieve the same thing either through scripting or expression for a numeric label.

The other thing I don’t understand is why I am getting multiple returned results in my table when I set it to a fixed sample size and average aggregation mode. Its always returning one average per day which is fine If my range is 8 hours, but when its a week it returns 7 results.

I believe this is similar or the same as using the system.tag.queryTagHistory() but what I dont understand is how to customise the time slice. If I say that I only want 1 result, thats what I want. The help file talks about a time slice but I cant see how I can customise this time slice to be the window I am trying to analyse, this is what the manual says:

"The return size determines how the underlying data is aggregated and/or interpolated. If a distinct return size is specified, that will be the number of rows in the resulting dataset. The special numbers 0 and -1 mean “Natural” and “On-Change”, respectively. “Natural” calculates a return size based on the rate of the logging historical scan classes. For example, if you query 1 hour of data for a scan class logging every minute, the natural return size is 60. “On-Change means that you’ll get an entry whenever any of the tags under consideration have changed.
The aggregation mode is used when the data is denser than what you asked for - there is more than 1 sample per time slice in the range you’re requesting. “MinMax” will return two entries per time slice - the min and the max. “Average” will return the average value of all samples in that time slice.”

If I cant get around the fact that it returns a dataset of multiple averages per time slice then I guess I will just average the column of averages with mean(dataset,column)

I must admit though, I am not having much luck scripting a table of results using system.tag.queryTagHistory()
I can get the results binding the tag history but scripting it I keep getting errors.


Unfortunately, I think your best bet currently is to do what you thought, and take the average of the dataset. In theory what you want to do with the queryTagHistory should work, using start=x, end=y, mode=avg, and returnSize=1. However, that call currently returns two values, one for the bounding value, and then the average for the rest of the time frame, leaving it not quite correct.

We are currently working on improving all of this in various ways. First, to make it much easier to run these types of queries through the queryTagHistory function, with more aggregate functions (numeric average vs. time weighted is one example), fixing how they work for 1 result, and new ways to specify time range. For example, to get the average over the last 8 hours, you would be able to simply do something like queryTagHistory(paths=[‘tag’], rangeHours=-8, aggregationMode=‘Average’, returnSize=1). This functionality should be available by the middle of May.

One other thing that I would suggest for right now, though: create your own version of the query function as a script module that queries for return size of 10 or so, and then does the averaging. That way you can then use it in multiple places.


This will help. Thank you.