# Multi coloured line graph

## Recommended Posts

Hi,

I have used your suggested boolean math system to get round the lack of variable colour threshholds in the graph component so that on the first of my graphs the expressions, (here I have two colour thresholds) are:

red - outside the target band:

`(ShiftAshDeviation*(Abs(ShiftAshDeviation)&gt;AshBand))+(NaN()*!(Abs(ShiftAshDeviation)&gt;AshBand))`

and

green - within the target band:

`ShiftAshDeviation*(Abs(ShiftAshDeviation)&lt;=AshBand)+(NaN()*!(Abs(ShiftAshDeviation)&lt;=AshBand))`

and on the second graph where there are three colour thresholds the expressions are:

yellow - above target + band but below upper limit:

`(RunningAsh*((RunningAsh&gt;=(AshTarget+AshBand))*(RunningAsh&lt;=AshHighLimit)))+(NaN()*!((RunningAsh&gt;=(AshTarget+AshBand))*(RunningAsh&lt;=AshHighLimit)))`

yellow - below target - band but above lower limit:

`(RunningAsh*((RunningAsh&gt;=AshLowLimit)*(RunningAsh&lt;=(AshTarget-AshBand))))+NaN()*!((RunningAsh&gt;=AshLowLimit)*(RunningAsh&lt;=(AshTarget-AshBand)))`

red - below low limit:

`(RunningAsh*(RunningAsh&lt;=AshLowLimit))+NaN()*!(RunningAsh&lt;=AshLowLimit)`

red - above high limit:

`RunningAsh*(RunningAsh&gt;=AshHighLimit)+(NaN()*!(RunningAsh&gt;=AshHighLimit))`

green - within the band about the target:

`(RunningAsh*(RunningAsh&gt;=(AshTarget-AshBand))*(RunningAsh&lt;=(AshTarget+AshBand)))+(NaN()*!((RunningAsh&gt;=(AshTarget-AshBand))*(RunningAsh&lt;=(AshTarget+AshBand))))`

where RunningAsh is a channel populated from the last values of the Ash chanel as:

`RunningAsh.AddValue(Mean(Ash[0,ResponseTime]))`

I used to use the Smooth function on the raw Ash channel in line in the expression but this made the expression even more unwieldy than it is now.

These expressions seem to generally give me what I want with two exceptions:

1) Occasionally the first graph momentarilly plots a few red points at the center zero line (its a deviation from target graph) which disapear as the next point is plotted (1 per second) This doesn't happen very often but is sufficiently frequent to be distracting when it happens. Is this something wrong with my boolean math?

2) If the data gooes outside the Y scale by a sufficiently large excursion then the coloured point will plot just beyond the desk area of the graph. I have tried externally clamping the data to the Y scale limits before it is added into the channel from which I plot the graph points. This obviously works but has the disadvantage that if the user subsequently increases the Y scale then the historical data plotted has been limited to the old Y scale and is thus not a valid representation any more. I wondered if the use of the inline (iif) statement could be used to do the limiting to Y scale in the graph expression for each colour but as the expressions for each coloured trace are rather complicated I was a bit wary of trying this. As the channel data plotted is referenced as a block rather than just the latest point does the graph component recalculate each point in the trace ready for each update of the graph display?

Two other points I have yet to sort out with the graphs are:

i) The format for the Y axis values. If the number of increments along the Y scale give each value such that they can be drawn as integers then the actual graph occupies a greater proportion of the whole display. How can I force the format to always show say one figure after the decimal point. I have tried the Format statement in the expression for the Y scaling but this doesn't seem to work. The Y scale minimum and Y scale maximum are variables.

ii) The X axis scaling (time) has the digits in a font size that makes it dificult to read and varies as the length of the graph varies due to the above (a)

Is there a way to fix the format of the Y axis and font size of the X axis so that the readability is not variable?

Thanks in advance for all the help.

Martin

##### Share on other sites

Instead of doing all this fancy math, maybe you just need another channel that holds the a code for each color, then in the Event for your incoming channel, figure out what color that particular data point should be drawn in.

##### Share on other sites

Sorry, But I don't Understand. Can you explain please.

Martin

##### Share on other sites

ok, lets say your channel name is "myChannel" and you want it to plot blue if the value is < 0, green if its < 2 (but >=0) and otherwise red. Create another channel called graphColor or similar, Device type Test, I/O type A to D, Timing = 0. Then in the event for myChannel:

```switch
case(mychannel[0] &lt; 0)
case(myChannel[0] &lt; 2)
default
endcase```

This will make graphColor have either 0, 1, or 2 depending on what color should be used. You can then use graphColor as the expression driving the trace colors for the myChannel trace in your graph.

##### Share on other sites

That is much better than the Boolean Math approach and more easily readable by the person that picks this project up when I am gone! I have tried it with a line type, a stick type and an area type plot. As it indicates in the help the area type plot does not support multi-coloured plotting. The line type works well, much better than I achieved with the Boolean Math method. The Stick type plot still has a "shuffling progression" along the chart due in part to the thickness of the sticks not being related to the length of the X axis.

My next point was as outlined in my point (2) earlier in this thread. Any use of this method by, say, setting a colour that was the same as the graph area to make the plot invisible would suffer as my earlier attempt when the Y scale was altered. One would have to re-evaluate externally the entries in the Graph colour channel, as filled by the main channel event code, any time the Y scale was altered.

The last point was the Format of the axis scales as in the points (i) and (ii) earlier in this thread. Is there any fix for this?

Thanks,

Martin