I am trying to represent a speed value in time with a sparkline. The data i am using is comming from the tag history of a tag that updates on value change and i want to represent the past two hours of speed values. However, when the value doesnt change for a while, instead of creating a plateau or step, it creates a slow incline to the next value. Is there a way to change this so it acts more like a step chart or is that not possible using Sparkline charts?
This wouldn't be too difficult to transform with scripting. Add a custom property to the chart called 'rawData'.
Then, bind your data source for the chart to the rawData
instead of the data
property.
Finally, use a property change script to transform the raw data into step chart data for the sparkline chart:
# Run only when the rawData parameter changes
if event.propertyName == 'rawData':
# Get the current raw data from the property change event
rawData = event.newValue
# Define the parameters that are needed to create a transformed dataset
headers = ['t_stamp', 'value']
transformedData = []
maxRowIndex = rawData.rowCount - 1 # Used to prevent overflow on the last data point
# Iterate through the raw data and add for each row added to the transformed data parameter,
# ... add a copy of the preceding data point to each successive time stamp
# ... so the chart will draw steps from point to point instead of angles
for row in xrange(rawData.rowCount):
transformedData.append([rawData.getValueAt(row, 't_stamp'), rawData.getValueAt(row, 'value')])
transformedData.append([rawData.getValueAt(min(maxRowIndex, row + 1), 't_stamp'), rawData.getValueAt(row, 'value')])
# Set the chart's data parameter to the transformed data
event.source.data = system.dataset.toDataSet(headers, transformedData)
Result:
2 Likes