Creating a Graph from Python Script

I’m looking to create a graph from a python script inside the console. Is this possible since most standard python libraries aren’t capable of being loaded into this version of jython? Or will I be confined to using the Easy Chart?

Thanks

What exactly are you trying to do, and why aren’t the easy chart or standard chart components sufficient for your needs?

I have not ran into anything yet that I couldn’t accomplish with those two components.

That being said, don’t forget that the real power of jython is the integration with java.

What kind of graph you want to draw or have in mind?can you give an example?

@lrose @PRAMANJ

Apologies for the brevity. I am trying to pull data from a unit on a line, graph this data, and perform check tests on them. If all pass, the unit moves through, and the data is deleted. However, if any tests are failed, the graph will be kept and displayed for a worker to determine the reason for failure and fix said reason.

I am very new to ignition, but a supervisor has mentioned to use a python script to do this rather than the easy chart for the fact that I will be using a python script to perform these check tests and will be deleting data of clean tests.

Thank you for your assistance.

Welcome to the party!!

You are still being vague, I assume because you’re being careful.

How is the data being pulled from the unit? Is the unit a PLC or some other type of device? What type of operations do these check tests include? What does the graph need to look like? Is there some type of color coding that needs to be done? etc…

You and/or your supervisor seem to believe that your end result is not possible with the out of the box components provided, nothing you have posted leads me to believe this is the case.

From what information you have provided it seems that the standard chart component would be your best bet. Creating a data set that the chart component can draw via script is one thing, actually drawing the chart is much more complex.

Need a little more information to really help you properly.

2 Likes

Yes it’s still vague! If you want some graphics like shapes using lines and circles to be drawn with animations it should be possible to do it like someone has developed the circular slider. If it’s something like a chart I guess it may be difficult to modify .

Yes, the data is from a PLC. There will be 5 ‘types’ of checks that will be done, each with multiple stages. The values being checked are floats. For example, if we took say a type 1 check, we would use a script to determine if the value was out of range, while graphing this data at the same time in order to quickly identify where the problem is arising. If we set the type 1 check 1 range to be from 0 to 10, and we received a value of 11.5, we would be alerted of the issue from a script, and we would be able to check the graph to see precisely where this occurred.

So, yes, it would be optimal to have 5 different colored lines being graphed with this data.

This being said, I have been playing around with the built in charting feature and it does seem to contain much more functionality than I first thought.

Yes the Chart component is very flexible. It can do what you are looking to achieve.

By default the Chart component has a Data property holding time-series data. The first column in this dataset is the time (x-coordinate) value for each of the values in the other columns. Each column after this then represents the values (y-coordinate) for a line on the graph. Adding more columns will add more graphed lines.

You can use the chart customizer to modify the x and y-axis, add additional axis, add additional datasets, and change how the data is rendered.

If you dig in really deep you can go so far as changing the color of individual points and more.

See this post for an example:

http://forum.inductiveautomation.com/t/change-color-of-one-point-in-a-xychart/24745

If you need help with something specific, don’t hesitate to ask.

1 Like

Have you considered storing the PLC data in the Historian? Is the analysis of the potential failure always done “in-situ” by the operator/inspector and the chart discarded afterwards? If the charts need to be kept, how do you envision that working?
Storing the raw data in Historian is relatively inexpensive, and pulling the data to create the chart you need on the fly should not be a problem (without knowing your scan rates and data volumes, mind you)
Also, consider using the tag’s alarm properties to perform your checks for out of spec/limits/range instead of offloading the work to scripting.

Cheers!

1 Like

lrose,

Can you provide an example of how to retrieve the Data property and unwrap some of it in python? I have interest in this process for a project of mine.

Sorry been fairly busy and it’s taken me a while to get to this.

Here is a simple example that will print out the contents of the charts Data property, just place it in a button’s actionPerformed event and it should work. You will need to make certain that the first line points to the chart of interest. In my case the chart is on the root container and is named chart.

#grab a reference to the chart Data property
dsChartData = event.source.parent.getComponent('Chart').Data

#this will grab the column headers of a dataset.  In this case the first column 
#will be your series data. (i. e. if your chart is using time series data then the
#first column will be named 't_stamp'
headers = system.dataset.getColumnHeaders(dsChartData)

#loop through the datasets rows, there will be 1 row for each 
#series data point (e.g. minute, hour, events, etc...)
for row in range(dsChartData.rowCount):
    #just using a dictionary for pretty print without much effort in the console
	rowData = {}
    #loop thorough each column in the data set.  The first column 
    #will be the series column and each subsequent column will 
    #represent a pen on the chart.
	for col in range(dsChartData.columnCount):
        #This line puts the data into the dictionary, I use the headers list as a key
        #and use the getValueAt function to get the value at that location
		rowData[headers[col]] = dsChartData.getValueAt(row,col)
	
    #This will print in the console in the following format:
    #{Column_1_Name: Column_1_Value,Column_2_Name: Column_2_Value,...Column_N_Name:Column_N_Value}
	print rowData

That’s fairly basic, so please let me know if that didn’t answer your question. Also, please note, this has been tested in 7.9.3 and should work in any build of 7.9 after that. I don’t know exactly what this looks like for 8.0 but I am sure it is similar, at least on the vision side of things.

Yes, this answers my questions nicely, thank you. I am able to extend or just plain use what you posted and it works just fine.

Thank You,
Leif

Hey Irose,
I have stucked on on point regarding Chart.
I want to update the x y co-ordinates lower and upper boundary using the numeric field, but not found this functionality in Chart properties.
Will you have suggestions for the same?

I couldn’t find it on the XYChart, but the TimeSeriesChart allows you to set up a min and max on an axis:

@pascal.fragnoud I think they’re wanting help with vision.

@Shivani_Shete Im not certain I understand what you’re after. Are you wanting to change the axis range or coordinates of a data point?

yes, want to change axis start and end points from a numeric field