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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Dynamically Add/Remove series displayed on a chart

ptc-6291975
1-Newbie

Dynamically Add/Remove series displayed on a chart

Hi,

 

I wish to find out the ways to dynamically generate the series for a time-series chart based on the user selection.

 

Example scenario as below:

1. There are multiple check-boxes (A,B,C,D,E,F) available for user. And user can check multiple check-boxes at a same time.

2. Then, only the selected series shall be displayed on the time-series chart. (Will use Check-box 'Changed' event to trigger the 'redraw').

3. All data will be pulled from a single data stream, with each row will contain data for all series (A,B,C,D,E,F) as defined in the datashape.

 

May I know what is the best way to achieve this required functionality? 

 

Is it possible to generate a new infotable from the queried datastream result, & the new infotable will be using a dynamically defined datashape (datashape generated in run time based on user selection of checkbox), then feed the new infotable to the time-series chart?

 

Any guidance is much appreciated.

 

Thanks!

8 REPLIES 8

Hello there? Is there any advise available? If my explanation is not clear please do let me know. Thanks.

adam11
5-Regular Member
(To:ptc-6291975)

Hi Yew,

Sorry for the delay. While you won't be able to dynamically define a DataShape, you can create a DataShape that captures all of the possible fields and populate those fields based on the user's selection. For example, your Service would take six inputs (A, B, C, D, E, F), determine the fields and values that should be returned based on those inputs, and return an +InfoTable +which you bind to the Time Series Chart.


Hope that helps.


Thanks,

Adam



Hi Adam,

Yes I agree with you on the Service creation which take 6 inputs (A,B,C,D,E,F) which I will bind them to the state of the check-boxes, which would help me to determine which series shall be returned based on user selection of the check-boxes.


The issue is, I will use the QueryStreamEntrieswithData for the STREAM that I used to record the time series data (all A,B,C,D,E,F series data in one stream). Then it will return me the records in infotable. However, binding this infotable directly to the chart will render all series in one chart, not based on user selection.


Shall I use any Infotable function to remove the 'unwanted' column (say C,D,E and keep A,B,F) in the infotable, before it is sent to the chart for display? If yes how to do so as I am not aware of any built-in infotable function that is suitable for that.


If that is not the concept/idea, would you please explain in further detailed with some sample code for my reference?


Thanks in advance.




adam11
5-Regular Member
(To:ptc-6291975)

Yew,

You can use

RemoveField()

to remove fields based on the user's selection. For example, a Service that has two BOOLEAN inputs (a, b) would have logic as follows:


// Get Stream entries here


if (a && !b)

{

  result.RemoveField("fieldB"); // RemoveField() takes the name of the field as input

}


else if (!a && b)

{

  result.RemoveField("fieldA");

}


else if (!a && !b)

{

  // Remove both fields

}


The one downside to this solution is the chart's legend, if displayed, will show all of the fields, regardless of the user's selection. Oh, and all of the if statements you will need to write too :-)


Thanks,

Adam



qn
1-Newbie
1-Newbie
(To:ptc-6291975)

Or you can use QueryNamedPropertyHistory with an InfoTable of properties based on user selection :

  • DataShape: PropertyNamesForChart(name, description)
  • New service ShowPropertiesForChart:
    • Inputs: boolean (from properties' checkbox)
    • Ouput: Infotable, DataShape: PropertyNamesForChart
    • Build the InfoTable with AddRow based on properties' name
  • In the Mashup, the ouput of ShowPropertiesForChart will be the input of QueryNamedPropertyHistory's parameter "propertyNames"

It worked for me. Hope it can help.

Hi Adam,


Thanks for the suggestion! The RemoveField() method works, and in fact, it works quite well as the 'unwanted' series legend are NOT shown at all. Work just as what I expect it to be.


Also, instead of writing all possible combination of checkboxes, I just check the states of checkboxes with multiple IF instead of IF/ELSE. That reduces the code to be written but of course consume little more computing power but I think should be negligible. 


One last question on this: 

I tried to search Resources-Infotable functions before but couldn't see 'RemoveField()'. It is NOT exist under the Services SNIPPET section as well. So my question is, where should I go to look for possible built-in services in normal circumstances? That would help me to self-help before checking with you all in future.


Thanks in advance for your suggestion.



The Wiki has the full documentation.

RemoveFields would be in: 05.01.03.12.01 Additional Script Methods for InfoTables

Ok Got it. Thanks Pai!

Top Tags