05-20-2015 04:02 PM - edited 05-20-2015 04:08 PM
I found this thread but the code in the last example doesn't compile in latest Measurement Studio
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
Solved! Go to Solution.
05-20-2015 04:55 PM
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.
05-21-2015 12:03 PM
Thanks, very helpful.
07-12-2017 04:20 AM
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
07-12-2017 09:08 AM
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...
07-12-2017 11:31 AM
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.