Selectable Graphing


Doughboyjtd

Recommended Posts

I'm going to be graphing up to 5 different traces from 5 channels on one graph. I would like to make 5 toggle buttons somewhere on the page, one for each trace, so I can graph any combination of traces at a time. Basically I need to be able to turn on or off any of the 5 traces. How would I go about doing this?

Link to comment
Share on other sites

Sorry, not really even close. You need to declare some variables (from StartUp in QuickModPro):

// graphtraces is an array of booleans, 1 if the channel should be graphed, 0 if not.  Default is only the first.
global graphtraces = fill(0,CHANCOUNT)
graphtraces[0] = 1
// this temptraces is used to update the graph from UpdateTypeCombo.  Compares it to graphtraces and if a change
// is detected, updates the graph.
global temptraces = fill(-1,CHANCOUNT)
global tracenames = {"Pressure1","Pressure2","Flow1","Flow2","FlowTotal"}
global tracecolors
tracecolors[0] = rgb(0,0,0xff)
tracecolors[1] = rgb(0xff,0,0)
tracecolors[2] = rgb(0,0x80,0)
tracecolors[3] = rgb(0x80,0x80,0)
tracecolors[4] = rgb(0,0,0x80)

Then inside the while() loop in UpdateTypeCombo (which you probably can rename to something more appropriate):

	  if (min(temptraces == graphtraces) == 0) // this is a trick to compare an entire array.  
		 // If min == 0, then at least one element didn't match
		 temptraces = graphtraces
		 component.maingraph.DeleteAllTraces()	  
		 for (private x = 0, x < numrows(graphtraces), x++)
			if(!graphtraces[x])
			   continue
			endif
			component.maingraph.AddTrace(traceNames[x])
			// CurrentScaleFrom and CurrentScaleTo are internal variables of the axes that hold the current scaling of the bottom axis.  
			// This can vary from our variables if the user zooms or pans the graph
			execute("component.maingraph." + traceNames[x] + ".strYExpression = '" + traceNames[x] + "[BottomAxis.CurrentScaleFrom,BottomAxis.CurrentScaleTo]'")
			execute("component.maingraph." + traceNames[x] + ".color = " + doubletostr(tracecolors[x]))
		 endfor
	  endif

Finally, you need to name your graph "maingraph"

Link to comment
Share on other sites

Yes, you need it to toggle, and you can't use [Pressure1] unless Pressure1 is a variable (equal to 0 if you use my script).

You just want:

graphtraces[0] = !graphtraces[0]

or use the toggle between action.

For pressure2 it'd be [1], etc. It has to match up with the ordering of the tracenames variable.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.