cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Add limit lines to a Time Series Chart

lorenmc
1-Visitor

Add limit lines to a Time Series Chart

What is the best way to add limit lines to a Time Series Chart?  I have a property of my Thing that is an upper limit and I would like to display that on a Time Series chart along with the time varying data.

Thanks

Loren

14 REPLIES 14
adam11
7-Bedrock
(To:lorenmc)

Hi Loren,

The easiest (and only) way to add limit lines to a Time Series Chart is to add an additional column to your data containing the limit value for each record. Depending on your current implementation, you may need to create a wrapper Service that adds the additional column or modify your existing Service. In both cases, you'll want to use

DeriveFields()

to add the additional column. The code snippet for

DeriveFields()

is available from the Snippets tab.


DeriveFields()

 takes an expression parameter, which you can use to perform a calculation or simply pass in a numeric constant.


Thanks,

Adam



qn
12-Amethyst
12-Amethyst
(To:adam11)

Hi Adam,

DeriveFields()​​'s expression parameter accept only a constant value, or a calculation based on existing fields of data. How can I use a variable in expression parameter, for example, a limit given by user ? I tried to give the name of the variable, and I get the error "Script evaluation error : ReferenceError: "myLimit" is not defined."

Thanks,

Quang-Dung

paic
12-Amethyst
(To:qn)

Derive fields can take 'any expression' like .5*[FieldName] to create a value based on a column of the table.

or even Things[MyCalculator].LimitCalc({Parameter:[FieldName]}) to invoke a service.

qn
12-Amethyst
12-Amethyst
(To:paic)

Ok, but it does not take an input parameter of a service which calls DeriveFields, doesn't it ?

paic
12-Amethyst
(To:qn)

You could do the following.

Assign the Input parameter to a temporary Property.

Have a Service that retrieves that Property

Call that service in the Expression statement of DeriveFields.

Sorry the intent of DeriveFields just never thought of that scenario, most of the times one would assume an iteration through the Table and adding that Field value, but DeriveFields may prove to be more efficient.

qn
12-Amethyst
12-Amethyst
(To:paic)

Yes, that's what I've thought about. Could Expression take directly the temporary property, for example expression: "Thing[MyThing].myProperty ?

Having some limit lines would be a nice feature for diffent types of chart, more convenient than adding the same constant to every row of property history, then load every single constant on the chart. I'd like to know if you had already an enhancement request about that.

paic
12-Amethyst
(To:qn)

Ah good thought, never tried! Shouldn't be hard to try and confirm.

paic
12-Amethyst
(To:qn)

It works.

qn
12-Amethyst
12-Amethyst
(To:paic)

Yes, but the same problem, the name of myThing must be returned by another service. How could I do this without using "me.name" ?

paic
12-Amethyst
(To:qn)

Sorry that me.name can't be used, since it is interpreting everything within the context of the InfoTable assigned.

The use of a property and calling a known service should still work though I think.

What makes me.name necessary?

qn
12-Amethyst
12-Amethyst
(To:qn)

Because myTemporaryProperty is binded with myThing. Every myThing has a different limit values, so different myTemporaryProperty.

qn
12-Amethyst
12-Amethyst
(To:qn)

It's even not possible to use DeriveFields to add a new column of type STRING with the name of myThing in "epxression". It's considered like a field in the InfoTable assigned, and not a constant value !

I think I need to log the thing's name in ValueStream too. So it's possible to call different services by using the "ThingName" column of the InfoTable assigned.

wahmed
3-Newcomer
(To:lorenmc)

Can someone actually help me to use a property to put an upper limit on time series? Please guide me on how to use DeriveFields to use a parameter and how to further use it?

qngo
12-Amethyst
(To:wahmed)

If your Thing is "MyThing" and the property "UpperLimit" is the limit for the Time Series Chart, you can use the code below to add the column limit to your data before return to the chart:

var data = ...;

var params = {

  types: "NUMBER" /* STRING */,

  t: data /* INFOTABLE */,

  columns: "limit" /* STRING */,

  expressions: 'Things["MyThing"].UpperLimit' /* STRING */

};

var result = Resources["InfoTableFunctions"].DeriveFields(params);

Announcements


Top Tags