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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

Time Breakout Chart

wtaylor1
7-Bedrock

Time Breakout Chart

I am using ThingWorx Platform Release 9.3 and DatecodeSP9

I am using the Bar Chart widget and using it as a column chart. I need help developing the service to get the data into an infotable that will have runtime in minutes for every 20 minutes with planned downtime in certain columns (3-4). I have an example of what the customer wants it to look like.
2 REPLIES 2
CharlesJi
14-Alexandrite
(To:wtaylor1)

Hi @wtaylor1 , I think you can try to use the Auto Refresh function to refresh the data source service to have it updated every 20 minutes.

Here is the example of the chart I am trying to populate:

 

wtaylor1_0-1726146899546.png

 

 

Here is the Here is the code I am trying to use. 

// Create a new service in ThingWorx

// Name: CreateRuntimeInfoTable

// Inputs: MashDate & Runtime_Min_Total

// Outputs: INFOTABLE (DataShape: RuntimeDataShape)

 

var result = Resources['InfoTableFunctions'].CreateInfoTableFromDataShape({

    infoTableName: "InfoTable",

    dataShapeName: "OEETImeBreakChart_DS",

  });

 

  // Define the start time and end time

  var startTime = MashupDate;

  startTime.setHours(6, 0, 0, 0); // 6:00 AM

  var endTime = new Date();

  endTime.setHours(18, 0, 0, 0); // 6:00 PM

 

  // Define the interval in milliseconds (20 minutes)

  var interval = 20 * 60 * 1000;

 

  // Loop through the time range and add rows to the InfoTable

  for (var time = startTime.getTime(); time <= endTime.getTime(); time += interval) {

      // Query the Value Stream for the runtime value at the specific time

      var query = {

          oldestFirst: true,

          maxItems: 1,

          query: {

              filters: {

                type: "AND",

                filters: [

                    {

                    type: "EQ",

                    fieldName: "timestamp",

                    value: dateFormat(new Date(time), "00:00:000"),

                    },

                    {

                    type: "EQ",

                    fieldName: "Runtime_Min_Total",

                    value: Things["KepConn_TruLaserWeldNPP"].Runtime_Min_Total,

                    },

                ],

            }

        },

      };

     

      var streamEntries = Things["KepConn_TruLaserWeldNPP"].QueryNamedPropertyHistory(query);

      var runtimeValue = 0;

      if (streamEntries.rows.length > 0) {

          runtimeValue = streamEntries.rows[0].Runtime_Min_Total; // Replace 'Runtime' with the actual property name

      }

      var row = {

          timestamp: new Date(time),

          Runtime_Min_Total: runtimeValue

      };

      result.AddRow(row);

  }

  // Return the InfoTable

  var output = result;

Announcements


Top Tags