Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Draw gridlines in the run-time

Hi everybody,

 

I build a real-time plot on the base of scattergraph where Axis X is in stripchart mode. Now I would like to set vertical gridlines' interval during run-time and one of the gridlines  to pass through the certain point.

 

For example, I would like to move my gridlines so one of them was in the point marked with the red color (please see screenshot)

 

Does anybody has any idea how to do it?

 

Thanx

 

0 Kudos
Message 1 of 5
(3,770 Views)

Hi there,

 

Option 1)

You can enable the grid lines by XAxis.MajorDivision.GridVisible and XAxis.MinorDivision.GridVisible properties.

You can control the numbr of grids within two subsequent major divisions by using XAxis.AutoMinorDivisionFrequency property.

This should serve the purpose.

 

Option2)

If you want grid to pass through specific data point, then you might need to do some tricks 🙂

See the following code snippet.I have attached a picture I got from the code snippet below.

 

 

private void scatterGraph1_BeforeDrawPlotArea(object sender, NationalInstruments.UI.BeforeDrawEventArgs e)
{
    double mySampleValue = 44.75;

    // For the vertical grid, we have the y-coordintes.
    // e.Bounds.Top and e.Bounds.Bottom are the y-coordinates for the grid.
    // We just need to get the x coordinate of the grid.
    int xValue = MapDataValueToAxisCoordinate(xAxis1.Range, mySampleValue, e.Bounds.Left, e.Bounds.Width);

    // Create two points that joins the grid.
    Point upperPoint = new Point(xValue, e.Bounds.Top);
    Point lowerPoint = new Point(xValue, e.Bounds.Bottom);

    // Draw the grid.
    e.Graphics.DrawLine(new Pen(Color.Red), upperPoint, lowerPoint);
}

private int MapDataValueToAxisCoordinate(Range axisDataRange, double dataValue, int axisStartPoint, int axisClientSize)
{
    return (int)(axisStartPoint + (dataValue - axisDataRange.Minimum) * axisClientSize / axisDataRange.Interval);
}

 

 

Hope this was helpful. Reply if you need more help.

 

Vijet Patankar,

National Instruments

0 Kudos
Message 2 of 5
(3,755 Views)

Hi Vijet,

 

Thank you for your answer, but my problem is following:

 

my grid is moving from right to left in real-time and it is infinite, so I just want to move dynamicaly all gridlines so one of them was on this point and all ticks which are expected to appear will be in a special distance (interval) from this point. If I follow your advice I am afraid, that my chart will be too slow after some number of lines (for example when there are a lot of annotations the speed becomes very slow).

 

thank you Pit

 

0 Kudos
Message 3 of 5
(3,746 Views)

What do you mean by "special distance (interval)"? If your chart is scrolling, could you just scroll the line and then remove it when it scrolls offscreen? Are all your girdlines custom or is there just one custom gridline? Is this gridline a marking something? Maybe if you can give us some background we can help a little better.

National Instruments
0 Kudos
Message 4 of 5
(3,714 Views)

Hi Petrucho,

 

I understand that you are charting data that seems to move from right to left, and I think I understand that the number of grids are infinite, meaning they are continously spaced at some distance from each other.

 

But, we dont have to draw grid lines that are outside of XAxis.Range. The graph displays plots within the bounds defined by the x-axis and y-axis. So you can use the Range  of axes to calculate how many grid lines and at what points those grid lines should be displayed. That is, you do not need to calculate and draw grid lines that are outside the axes ranges. Even if you try drawing something outside the plot area, it is just clipped off 🙂 It wont get drawn.

 

For example, If I wanted to display grid lines at multiple of 4 on x-axis, what I would do is,

 

a) Calculate multiples of 4 that lies within xaxis.Range.Minimum and xaxis.Range.Maximum [I will use some basic arithmetic for this].

b) When each value is calculated, I will use the code (from my previous reply) to draw the grid line.

 

It should not matter if the graph is in charting mode or the xaxis range is changing real-time. All that you'd need is to calculate at what points (within the boudaries of XAxis) you want the grids to be drawn.

 

Let ut know if this helped.

If you need more help, please write the description in detail and possibly attach diagram about how the graph should look.

 

Vijet Patankar

National Instruments.

0 Kudos
Message 5 of 5
(3,681 Views)