Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically change Intensity Graph color scale C#

Solved!
Go to solution

I found this thread but the code in the last example doesn't compile in latest Measurement Studio

http://forums.ni.com/t5/Measurement-Studio-for-NET/Change-the-Color-Map-of-the-Intensity-Graph-at-Ru...

 

  • IntensityColorMap is unknown
  • not sure what intensityPlot1 is (I only have an IntensityGraph object)
  • intensityGraph.ColorScales[0] doesn't exist

 

 

I have 2 questions:

1.  What's the best way to change the range of the IntensityGraph color map?

2.  Is there a setting to make it all automatic based on Max/Min?  I mean, just set Max/Mix/Number of steps and it does it all for you?  Maybe there's a setting to set it all automatically based on data?

 

Thank you in advance

0 Kudos
Message 1 of 6
(6,439 Views)
Solution
Accepted by topic author kirko7

That example is for the Windows Forms intensity graph. In WPF, you would initialize the Markers collection on the ColorScale assigned to the IntensityGraph with the collection of colors you want. To make the color scale automatically adjust to the data, set the Adjuster property to a value like FitExactly and the color scale will update the positions of the markers when the data range changes.

~ Paul H
0 Kudos
Message 2 of 6
(6,433 Views)

Thanks, very helpful.

 

0 Kudos
Message 3 of 6
(6,406 Views)

I have a question on the same topic:

I have a LineGraph and an IntensityGraph in one <ni:Graph> Control. The WPF-Code looks like this:

 

<ni:Graph x:Name="pdGraph">
	<ni:Graph.Plots>
		<ni:Plot Name="pdPlot">
			<ni:IntensityPlotRenderer                                              
				ColorScale="{StaticResource colorScale}"/>
		</ni:Plot>
		<ni:Plot Name="pdSinePlot">
			<ni:LinePlotRenderer Stroke="Black"/>
		</ni:Plot>
	</ni:Graph.Plots>
</ni:Graph>
<niPrimitives:ScaleHost 
	niPrimitives:LayeredGraph.TargetOrientation="Vertical"
	niPrimitives:LayeredGraph.TargetPosition="Far"
	Owner="{Binding ElementName=pdGraph}"
	Scale="{StaticResource colorScale}" />

 

The colorscale WPF looks like this:

 

<Window.Resources>
	<ni:ColorScale x:Key="colorScale"
			Adjuster="FitExactly">
		<ni:ColorScaleMarker Color="Transparent" Value="0"/>
		<ni:ColorScaleMarker Color="#FF041BFF" Value="1"/>
		<ni:ColorScaleMarker Color="#9926FF04" Value="25"/>
		<ni:ColorScaleMarker Color="#CCFFFF00" Value="50"/>
		<ni:ColorScaleMarker Color="Red" Value="100"/>
	</ni:ColorScale>
</Window.Resources>

 

The according Intensity Data changes during runtime, and as the Adjuster is set to "FitExactly", the colorScale also adapts accordingly.

My problem is the following:

I want the "Values" for the first two colors to always stay 0 and 1, that independently of the highest Intensity data values, if there is a value of 1, the color is "#FF041BFF", and not something between "Transparent" and "#FF041BFF" (as it is now, because the whole "color range" is scaled according to the highest intensity data values).

I tried to bind the "Value" to a "StaticResource" like:

    <Window.Resources>
        <sys:Double x:Key="fixedZero">0</sys:Double>
        <ni:ColorScale x:Key="colorScale"
                       Adjuster="FitExactly">
            <ni:ColorScaleMarker Color="Transparent" Value="StaticResource fixedZero}"/>
[...]

but this does not work.

Also, as I do not have the IntensityGraph control, I don't know how to access my colorScale in code behind during runtime.

Thanks for any hints on this

0 Kudos
Message 4 of 6
(4,111 Views)

Edit:

I made a workaround by eliminating the Point3Ds, that have a Z-Value of 0 (Therefor I don't need transparent datapoints). Anyway I would be interested how this may work...

0 Kudos
Message 5 of 6
(4,104 Views)


I made a workaround by eliminating the Point3Ds, that have a Z-Value of 0 (Therefor I don't need transparent datapoints).

Note that double.NaN is always rendered as transparent (to indicate a missing value in the data). Though I agree the best approach is to remove unnecessary values.

 

Also, as I do not have the IntensityGraph control, I don't know how to access my colorScale in code behind during runtime.

When you declared the color scale in your XAML as "<Window.Resources> <ni:ColorScale x:Key="colorScale" ...", that added the color scale to the Resources collection on your window. To access it, you can use code like "var colorScale = (ColorScale)Resources["colorScale"];".

 

I want the "Values" for the first [color to always stay 1], that independently of the highest Intensity data values, if there is a value of 1, the color is "#FF041BFF", and not something between "Transparent" and "#FF041BFF" (as it is now, because the whole "color range" is scaled according to the highest intensity data values).

With the simplified requirement (only the first value needs to remain constant), you could use a custom RangeAdjuster to ensure the returned range has a fixed minimum.

 

More generally, since the range adjuster does not have access to the color scale (and you would not really want to modify the scale while it is being adjusted), it would be better to correct the Markers collection after the fact. Specifically, you could register for the CollectionChanged event, determine whether the color markers are correct, and replace any markers that are out of sync.

~ Paul H
0 Kudos
Message 6 of 6
(4,098 Views)