Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Any code examples of scatterplot point color usage.

We would like to plot arbitrary points in unique colors. Using the following code, plotted points show only the default color.
If, instead of scatterPlotDiff.PointColor, the scatterPlotDiff.LineColor property is used,
the whole line, but not individual points, changes to the new color.
How can each point be plotted in a unique color?
thanks.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
for(int j = 0; j < i; j++)
{
diffTrace[j] = trace1[j] - trace2[j];
if (diffTrace[j] > .1) )
scatterPlotDiff.PointColor = Color.Red;
else if (diffTrace[j] > .05)
scatterPlotDiff.PointColor = Color.Yellow;
else
scatterPlotDiff.PointColor = Color.Green;
if (j == 0)
scatterPlotDiff.PlotXY(freq1[0],diffTra
ce[0]);
else
scatterPlotDiff.PlotXYAppend(freq1[j],diffTrace[j]);
}//for j
0 Kudos
Message 1 of 6
(4,464 Views)
You can do this via a custom point style. The PointStyle type looks and feels like an enum, but if you look at its definition you'll notice that it's actually an abstract base class and that its values are actually static properties that return implementations of that base class. This provides the ease of use of an enum, but actually lets you define custom values with extended behavior, which cannot be done with a normal enum. Several types in the Measurement Studio UI assembly follow this pattern, including LineStyle, Border, LedStyle, SwitchStyle, etc. Some of these types, including PointStyle, also have the concept of value dependency, which allows the type to have different behavior depending on the context that it's used. For the PointStyle, this context could be the value.

For example, in your code example, you wanted to have a red point style when the value is greater than .1, a yellow point style when the value was > .05 and < .1, and a green point style for any other value. The point style below demonstrates how to do this and also takes it a step further by also displaying different styles for these different ranges:

class DynamicPointStyle : PointStyle
{
public override bool IsValueDependent
{
get
{
// Specify value dependency since we want different colors
// depending on the value of the point.
return true;
}
}

public override void Draw(object context, PointStyleDrawArgs args)
{
double yValue = args.Y;
if (yValue > .1)
PointStyle.Plus.Draw(context, CreateArgs(args, Color.Red));
else if (yValue > .05)
PointStyle.EmptyCircle.Draw(context, CreateArgs(args, Color.Yellow));
else
PointStyle.SolidCircle.Draw(context, CreateArgs(args, Color.Green));
}

private static PointStyleDrawArgs CreateArgs(PointStyleDrawArgs args, Color color)
{
return new PointStyleDrawArgs(args.Graphics, color, args.Size);
}
}

To test this class, create a new Windows Forms project, add a ScatterGraph to the form, and add the following code to the form:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

const int dataLength = 50;
double[] xData = new double[dataLength], yData = new double[dataLength];

Random rnd = new Random();
for (int i = 0; i < dataLength; ++i)
{
xData[i] = i;
yData[i] = rnd.NextDouble() * 0.25;
}

scatterGraph1.PlotXY(xData, yData);

scatterPlot1.LineStyle = LineStyle.None;
scatterPlot1.PointStyle = new DynamicPointStyle();
}

Run the application and you'll see a result similar to the screenshot attached below. For another custom point style example or to see examples of creating a custom line style or border, see the CustomStyles example that ships with Measurement Studio 7.0.

- Elton
Message 2 of 6
(4,464 Views)
Is There a way to have the points color depend on a external parameter? Without having all the points change color?

JMD
0 Kudos
Message 3 of 6
(4,464 Views)
I think there will be a way to do what you want, but I'm not 100% sure of what you're looking for. Can you give an example of what you're trying to do?

- Elton
0 Kudos
Message 4 of 6
(4,464 Views)
I take data from multiple triggers and then average and plot the data. What happens is that the new data overlaps the old data, and I can't tell where on the plot the new data is being add. Is there a way to change the pointcolor of only the new data on the waveform. Or would it be possible to have the newest data point be larger in size than the previous. When a new point is added, change the size of the previous point to the default. Then add the new point that is larger.

I want to be able to tell where data is add to the graph. Thanks

JMD
0 Kudos
Message 5 of 6
(4,464 Views)
I think that the easiest way to do this would be to have two plots in the graph, one for old data and one for new data, and then configure the line/point colors/styles on each plot to distinguish the old data from the new data. When you get new data, you could could call GetXData/GetYData on the new plot, pass that data to PlotXYAppend on the old plot, then plot the new data via PlotXY on the new plot.

- Elton
0 Kudos
Message 6 of 6
(4,464 Views)