Scripting Time Series: Series, Trends and Axes

I would like some help with scripting the series, trends and axes. I use a script to generate an array of positions, which is used in a transform to generate the series, as well as the trends.

The current end result is an empty time series chart with three axes.

Here is my project script:

def buildZonePositions02(zone):
	"""
	Returns a list of dicts describing all valid positions for one zone.
	"""
	zone = int(zone)
	if zone == 11:
	    return []
	
	# Zones with 4 positions
	posCount = 4 if zone in (6, 7, 8) else 3
	
	positions = []
	zoneName = "PS %02d" % zone
	zoneStr = "%02d" % zone
	
	for p in range(1, posCount + 1):
	
	    # Exclusion: PS 05-3
	    if zone == 5 and p == 3:
	        continue
	
	    posLabel = "%s-%d" % (zoneName, p)
	
	    psBase = (
	        "[default]Folder/Power Supplies/"
	        "%s/Display/" % posLabel
	    )
	
	    positions.append({
	        "zone": zone,
	        "position": p,
	        "label": posLabel,
	        "kw": psBase + "KW",
	        "amps": psBase + "Amps",
	        "volts": psBase + "Volts"
	    })
	
	return positions

This is the transform that calls the script, binding on self.custom.positions

positions = Coater.Power_Supply_Trending.buildZonePositions02(self.custom.zone)
return positions

Series transform:

# self.custom.series binding on self.custom.positions:
	series = []
	
	colors = ["#4CAF50", "#2196F3", "#FF9800", "#9C27B0"]
	
	for i, pos in enumerate(value):
	    color = colors[i % len(colors)]
	
	    series.append({
	        "name": pos["label"] + " KW",
	        "data": pos["kw"]#
	    })
	
	return series

Trend transform:

# self.custom.trends binding on self.custom.positions:
	trends = []
	for i, pos in enumerate(value):
	#	print(i, pos)
		trends.append({
			'visible': True,
			'type':'line',
			'series':'kw',
			'interpolation':'curveLinear',
			'axis':'Power',
			'columns':{
				'key':pos['label'] + ' KW',
				'color':'#00FF00'
			}
		})
	return trends

Axes configuration:

# Current axes configuration, self.custom.axes:
[
  {
    "name": "Power",
    "min": 0,
    "max": 100,
    "alignment": "right",
    "width": 30,
    "label": {
      "visible": true,
      "text": "",
      "offset": 0,
      "font": {
        "color": "",
        "size": 10
      },
      "style": {
        "classes": ""
      }
    },
    "tick": {
      "color": "",
      "count": "Auto",
      "label": {
        "format": "Auto",
        "font": {
          "color": "",
          "size": 10
        },
        "style": {
          "classes": ""
        }
      },
      "style": {
        "classes": ""
      }
    },
    "grid": {
      "visible": false,
      "color": "",
      "opacity": 0.9,
      "dashArray": 0,
      "style": {
        "classes": ""
      }
    },
    "style": {
      "classes": ""
    }
  }
]

So the custom props look like this:

Chart's props.series[0]:

{
  "name": "PS 03-1 KW",
  "data": {
    "path": "[default]/Folder/PS 03-1/Display/KW",
    "source": "tag"
  }
}

trends[0]:

{
  "visible": true,
  "type": "line",
  "series": "PS 03-1 KW",
  "interpolation": "curveLinear",
  "axis": "Power",
  "columns": [
    {
      "key": "PS 03-1 KW",
      "color": "#00FF00"
    }
  ],
  "baselines": []
}

But the chart looks like this:

What am I missing to get the tag's historical data to display?
And, why are there three axes?

Thank you!

that doesn’t look right, the “/” after the tag provider

Actually, that whole series object looks incorrect. props.series[0].data should contain an array of the data either as a dataset or as an object structure.

I see your screenshot is showing a custom series value, not the time series chart’s props.series though. What is the value of the latter?

1 Like

Probably fat-fingered that.

This is series[0]:

{
  "name": "PS 03-1 KW",
  "data": {
    "path": "[default]Folder/PS 03-1/Display/KW",
    "source": "tag"
  }
}

I realize that by using a tag history binding, I get an array of data, and that is what I hope to do through scripting, for a couple of reason.

  1. reuse the chart/embedded view
  2. the number of items to graph will vary
  3. the tags will vary - but I think I will just use a separate chart for different tags.

I’m not sure where this structure came from, but to use a tag history binding with dynamic tags, see here Tag History Bindings in Perspective | Ignition User Manual

Ie it should be like this:

[{...}]

... The forum still doesn't let me put multiple lines within code blocksnwhen I'm using my phone.. Even pasting fails too. I’ll fix later

Screenshot for now

Yeah, I understand that.

I guess I didn't make it clear early on, but the chart's properties are bound to those custom properties in the picture.

I was trying to build the series array using script. The bottom line question, then, is probably: Can this be done? Script the series, trends, axes as shown above?
I know some elements have additional properties you can add in manually, so I tried that with the series array. Series is like [{...}], but when copying a property object you don't get the property itself, just it's contents. So, as you can see in one of the pictures above, series[3], with several elements underneath it.

So, instead of chasing out how to do this, is it even possible?

You absolutely can script the whole thing. Easiest if your source data and config are in view custom props. I prefer to use iterating expressions via my toolkit, fwiw. Example of the latter in my exchange project for tag reporting/exporting.

Where do I find this project?

In the designer, go to File→Ignition Exchange. Phil's project link below:

2 Likes

He said there is an example in his project, but this is the download for the module. I do not understand where to find the example he spoke of.

That's not a module. Its a project with a view.

The download from the exchange includes a project file to import.

Separately, you will need my Integration Toolkit module, as the Exchange project depends on it. (Install the toolkit first.)