12-26-2012 11:22 AM
Hello,
Recently I've found out that the ColorScale class of the Intensity Graph has the ColorMap property as a read-only one. I am wondering if it is any way to change the ColorMap of the Intensity Graph at Run-time.
Thank you in advance.
12-27-2012 10:10 AM
Hi PLK,
I was able to change the ColorMap property of the IntensityPlot (a member of the Intensity Graph) using the following code (in C#, MStudio 2012, VStudio 2010):
intensityPlot1.ColorScale.ColorMap.Add(0, Color.FromArgb(redValue[0], greenValue[0], blueValue[0]));
intensityPlot1.ColorScale.ColorMap.Add(50, Color.FromArgb(redValue[1], greenValue[1], blueValue[1]));
intensityPlot1.ColorScale.ColorMap.Add(100, Color.FromArgb(redValue[2], greenValue[2], blueValue[2]));
If you try to change the intensityGraph1.ColorScale.ColorMap, the scale and plot won't line up. You have to change the color scale of the plot to see a change, and the color scale of the graph to change the legend.
Let me know if this gets you going in the right direction!
Regards,
Alexandra
12-28-2012 06:16 PM
Hi Alexandra,
Thanks for the right direction you have guided me to. In my opinion, it is more advantageous to use the AddRange member of the ColorMap object. It will add a whole color map at once. So, I've ended up with the following:
// Create the small Rainbow color map
double ScaleMin=intensityPlot1.ColorScale.Range.Minimum;
double ScaleMax=intensityPlot1.ColorScale.Range.Maximum;
double valLen=ScaleMax-ScaleMin;
double[] values={ScaleMin,ScaleMin+valLen/4,ScaleMin+valLen/2,ScaleMin+valLen/4*3,ScaleMax};
Color[] colors={Color.FromArgb(0,0,255),Color.FromArgb(0,255,255),Color.FromArgb(0,255,0),
Color.FromArgb(255,255,0),Color.FromArgb(255,0,0)};
IntensityColorMap cMap=new IntensityColorMap(values,colors);
Minimum and maximum values of the scale are required in more general case when the scale has the Auto-range property
// Change the color scale of the plot
intensityPlot1.ColorScale.LowColor=colors[0];
intensityPlot1.ColorScale.HighColor=colors[colors.Length-1];
intensityPlot1.ColorScale.ColorMap.Clear();
intensityPlot1.ColorScale.ColorMap.AddRange(cMap);
It is important to change the LowColor and HighColor of the ColorScale to the boundary colors of the new ColorMap, because it won't adjust them automatically
// Change the color map of the legend
intensityGraph1.ColorScales[0].LowColor=colors[0];
intensityGraph1.ColorScales[0].HighColor=colors[colors.Length-1];
intensityGraph1.ColorScales[0].ColorMap.Clear();
intensityGraph1.ColorScales[0].ColorMap.AddRange(cMap);
Following you tip I've done all changes on the ColorMap for the first element of the graph ColorScales array in order to adjust the graph legend as well. And finally
// Redraw the graph
intensityGraph1.Refresh();
This approach is working well. Thank you again for your help.
Sincerely,
Pavel