From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Limitting region annotation

I'm trying to color a region under one of the plots.
The coloring has to end at y=0 point and not go down to infinity.
I used the region shape type and it works perfectly as long as I don't try to associate the annonation to a plot.
when I do so the coloring doesn't stop at the required point.
I tried using the plygon type and it works, BUT the coloring is done on top of other plots and grids and it looks bad.

Is the any solution ?
0 Kudos
Message 1 of 3
(2,875 Views)
I think that you can do what you want by creating two plots - one for the annotation and one for the data. Make sure that the plot for the annotation is before the data plot in the plots collection so that the annotation will appear under your data. For example, create a new VB project, add a graph and a button to the form, double-click the button, and add the following code:

Private Sub Command1_Click()

Dim annotation As CWAnnotation
Set annotation = CWGraph1.Annotations.Add

annotation.plot = CWGraph1.Plots(1)
annotation.Caption = ""
annotation.Arrow.HeadStyle = cwArrowHeadNone
annotation.Arrow.LineStyle = cwLineNone
annotation.Shape.Type = cwShapeMinMaxRegion

D
im xCoordinates(1) As Double
Dim yCoordinates(1) As Double

xCoordinates(0) = 2
xCoordinates(1) = 8
yCoordinates(0) = 2
yCoordinates(1) = 8

annotation.Shape.xCoordinates = xCoordinates
annotation.Shape.yCoordinates = yCoordinates
annotation.Shape.FillVisible = True
annotation.Shape.Color = RGB(255, 0, 0)

Dim plot As CWPlot
Set plot = CWGraph1.Plots.Add

Dim data(10) As Double
Dim i As Integer

For i = 0 To 10
data(i) = Rnd * 10
Next

plot.PlotY data

End Sub

When you run this code you'll see a red colored region whose x coordinates goes from 2 to 8 and whose y coordinates also goes from 2 to 8. You'll see a plot of random data whose x coordinates goes from 0 to 10 and whose y coordinates also go from 0 to 10. The plot of data will appear over the annotation.

Plea
se try this and post how it worked out. Thanks.

- Elton
0 Kudos
Message 2 of 3
(2,875 Views)
Sorry ... I missed that this was the C++ forum. Instead of the directions above, create a new VC++ project, add a graph and a button to the dialog, add a class member for the graph called m_graph, and add the following code to the button's click event handler:

CNiAnnotation annotation = m_graph.Annotations.Add();
annotation.Plot = m_graph.Plots.Item(1);
annotation.Caption.Text = _T("");
annotation.Arrow.HeadStyle = CNiArrow::None;
annotation.Arrow.LineStyle = CNiArrow::LineNone;
annotation.Shape.Type = CNiShape::MinMaxRegion;

CNiReal64Vector coordinates;
coordinates.Append(2);
coordinates.Append(8);

annotation.Shape.XCoordinates = coordinates;
annotation.Shape.YCoordinates = coordinates;
annotation
.Shape.FillVisible = true;
annotation.Shape.Color = CNiColor(255, 0, 0);

CNiPlot plot = m_graph.Plots.Add();
CNiReal64Vector data(11);

for (int i = 0; i < 11; ++i)
data[i] = (rand() % 11);

plot.PlotY(data);

- Elton
0 Kudos
Message 3 of 3
(2,875 Views)