Saving a configuration of a power chart in runtime?

Hi everyone,

I’m using Perspective 8.1.2. I’m trying to figure out the best approach to save a configuration of the power chart in runtime (Pens and axes/plots). I’m not really sure where to start with this, so any help is appreciated. Preferably something that can be saved on the gateway and retrieved, rather than an SQL approach.

1 Like

If you don’t want to go sql, then the nest best thing would be dataset tags to store the various table data. It’s not a 5min thing to setup. I would make it work for both dataset tags and sql tables, or at least make it easy to convert the code for either

1 Like

I think datasets are probably going to align more with my ignition skillset, can you point me to an ignition doc which has the process for turning the JSON into a dataset? I’ve not seen it done before.

@michael2 I think you’r going on right way. I was facing same problem during last week now it’s cleared. Thanks to you for this. :slightly_smiling_face:

Look up jsonEncode and decode in the manual, in only on my phone atm

1 Like

Thanks Nick, I’ll have a look into this.

Managed to get this working. Created a dataset which had a column for each JSON string in the props of the power chart (config, pens, plots, etc.), which then saved it to a tag with a name defined by the user. Does the same thing in reverse to ‘open’ the saved config.

1 Like

I’m looking to do the same thing, but having trouble dealing with the JSON, I think, and conversions to get it out of and back into the Power Chart properties. Can you post some simple sample code that demonstrates what you have done with this? Thanks.

There is probably a better way of doing this, but this is the way I did it:

Saving to a tag:

config = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.config)
interaction = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.interaction)
axes = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.axes)
pens = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.pens)
plots = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.plots)
dataColumns = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.dataColumns)
title = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.title)
timeAxis = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.timeAxis)
legend = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.legend)
style = system.util.jsonEncode(self.parent.parent.getChild("PowerChart").props.style)
#put JSON Strings in dataset
headers = ['config','interaction','axes','pens','plots','dataColumns','title','timeAxis','legend','style']
rows = [[config,interaction,axes,pens,plots,dataColumns,title,timeAxis,legend,style]]
system.tag.write(FilePath, system.dataset.toDataSet(headers,rows))

Retrieving from a tag:

data = system.tag.read(FilePath).value
self.parent.parent.getChild("PowerChart").props.config = system.util.jsonDecode(data.getValueAt(0,0))
self.parent.parent.getChild("PowerChart").props.interaction = system.util.jsonDecode(data.getValueAt(0,1))
self.parent.parent.getChild("PowerChart").props.axes = system.util.jsonDecode(data.getValueAt(0,2))
self.parent.parent.getChild("PowerChart").props.pens = system.util.jsonDecode(data.getValueAt(0,3))
self.parent.parent.getChild("PowerChart").props.plots = system.util.jsonDecode(data.getValueAt(0,4))
self.parent.parent.getChild("PowerChart").props.dataColumns = system.util.jsonDecode(data.getValueAt(0,5))
self.parent.parent.getChild("PowerChart").props.title = system.util.jsonDecode(data.getValueAt(0,6))
self.parent.parent.getChild("PowerChart").props.timeAxis = system.util.jsonDecode(data.getValueAt(0,7))
self.parent.parent.getChild("PowerChart").props.legend = system.util.jsonDecode(data.getValueAt(0,8))
self.parent.parent.getChild("PowerChart").props.style = system.util.jsonDecode(data.getValueAt(0,9))

Thanks for sharing that!