Perspective PowerChart Pens Dataset - Solved

I have been attempting to migrate from Vision Easy Charts to Perspective Power Chart. I loaded the pen data to my smart chart via a named query. I have been trying to recreate the same with a Power Chart. I have the Pens bound to a dataset and corrected most of the column names, but the tag path is proving difficult.

The Perspective Smart Chart Pens have data as an object with the source and aggregateMode as properties. Is there a column name or SQL trick I can perform to set these values from a dataset? I realize I could create them via script, but I would prefer to using a dataset loaded via a named query.

----------------------Update - I found a solution --------------------------------------------------

I found a solution. I printed an instance of a pin and had to massage the JSON string a little. Load the JSON string into a dictionary. Set the properties in the dictionary from each row of data using custom method, “CreatePen”. Note: you must leave the JSON as a dictionary, as passing back an array of JSON strings does not work.

def LoadPenData(self):
	"""
	Custom method that can be invoked directly on this component.

	Arguments:
		self: A reference to the component that is invoking this function.
	"""
	import json
	
	## Get the data set from the named query reference.
	sqlPenData = self.custom.TrendGroupPenData
	sqlPenData = system.dataset.toPyDataSet(sqlPenData)
	
	## Get a reference for the power chart.
	powerChartHistory = self.getChild("PowerChartHistory")
	
	## Instaniate a new array.
	pensArray = []

	## Create a pen instance for each row in the dataset.
	for row in sqlPenData:
		pen = self.CreatePen(row)
		pensArray.append(pen)
	
	## Set the pens array to the new array.	
	powerChartHistory.props.pens = pensArray
def CreatePen(self, row):
	"""
	Custom method that can be invoked directly on this component.

	Arguments:
		self: A reference to the component that is invoking this function.
		row: 
	"""
	import json
	
	## JSON template for pen data
	pen = '{"visible": true, "data": {"aggregateMode": "default", "source": ""}, "plot": "0L", "selectable": true, "display": {"interpolation": "curveLinear", "breakLine": true, "styles": {"normal": {"fill": {"color": "#63BEA2", "opacity": 0.8}, "stroke": {"color": "#63BEA2", "width": "1L", "dashArray": "0L", "opacity": 0.8}}, "highlighted": {"fill": {"color": "#63BEA2", "opacity": "1L"}, "stroke": {"color": "#63BEA2", "width": "1L", "dashArray": "0L", "opacity": "1L"}}, "muted": {"fill": {"color": "#63BEA2", "opacity": 0.4}, "stroke": {"color": "#63BEA2", "width": "1L", "dashArray": "0L", "opacity": 0.4}}, "selected": {"fill": {"color": "#63BEA2", "opacity": "1L"}, "stroke": {"color": "#63BEA2", "width": "1L", "dashArray": "0L", "opacity": "1L"}}}, "type": "line", "radius": "3L"}, "name": "", "axis": "", "enabled": true}'
	
	## Load pen string into a dictionary.
	pen = json.loads(pen)

	## Set properties.
	pen["data"]["source"] = row["TagPath"]
	pen["data"]["aggregateMode"] = row["AggregationMode"]
	pen["name"] = row["Name"]
	pen["plot"] = row["SubPlot"]
	pen["visible"] = row["Visible"]
	pen["selectable"] = row["UserSelectable"]
	pen["axis"] = row["Axis"]
	
	## Set the color for all styles.
	pen["display"]["styles"]["normal"]["stroke"]["color"] = row["ColorHex"]
	pen["display"]["styles"]["highlighted"]["stroke"]["color"] = row["ColorHex"]
	pen["display"]["styles"]["selected"]["stroke"]["color"] = row["ColorHex"]
	pen["display"]["styles"]["muted"]["stroke"]["color"] = row["ColorHex"]
	
	## Return the pen as a dictionary (do not dump to string).
	return pen
1 Like