Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Drawing information over a scattergraph

Hi,

 

Is there a way I can draw some text over a scattergraph? I thought of using XYPointAnnotation, but it is linked to the X / Y axes... I would need to draw information on the bottom right of the whole graph, like the following picture (the "2t" text and its border)

 

2010-01-22_145309.jpg

 

In this image, I was overriding the OnPaint method and I was drawing in the Graphics object. However, I ran into problems when I used the ToClipboard() method.

 

I also tried to create my own Annotation class, but XYAnnotation's constructor is internal so I cannot access it... 

 

Also note that the text must stay in the bottom right side even if the graph is panned / zoomed. In fact, what would be the best would be a XYAnnotation based on screen points instead of range value..

 

 

Is there a way I can accomplish this?

 

Thank you very much.

0 Kudos
Message 1 of 6
(4,336 Views)

Hi marvin966,

 

You can directly print text onto the graph using the Graphics.DrawString method.  An example of where you can use this method would be in the BeforeDrawPlotArea method.  Here is a snippet of code that should achieve the behavior that you are looking for:

 

 private void xyDataScatterGraph_BeforeDrawPlotArea(object sender, NationalInstruments.UI.BeforeDrawEventArgs e)
        {
            String message = "2τ";
            int fontSize = 12;
            Font charFont = new Font("Times New Roman", fontSize);
            int messageLength = message.Length * fontSize;
            e.Graphics.DrawString(message, charFont, Brushes.Snow, new PointF((e.Bounds.X + e.Bounds.Width) - messageLength,

                     (e.Bounds.Y+e.Bounds.Height)- charFont.Height));
        }

 

Please let me know if you have any questions about this method.

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(4,303 Views)

Hi Kelly R,

 

Thank you for your response.

 

Using this method solves a part of my problem. Indeed, the string I draw in BeforeDrawPlotArea stays when I use ToClipboard().

 

However, if I do it in this method, I am unable to place the label where I want to. (as in my previous post, the item is drawn at the bottom right edge of the graph, outside the plot area. Here is a picture of what I am getting using your method;

 

2010-01-26_092624.jpg

 

Is there some other place I can draw the string so that it would be over the axis?

 

I also have another requirement, when the graph is disabled, the label must not be black, it must be grayed out like the rest of the graph. Using your method fills this requirement perfectly, but my previous method (drawing string in OnPaint) did not.

 

Here is the code I am using to draw:

 

protected override void OnBeforeDrawPlotArea(BeforeDrawEventArgs e) { base.OnBeforeDrawPlotArea(e); SizeF textSize = e.Graphics.MeasureString(this.tauValue + "t", new Font("Symbol", 8f)); RectangleF rect = new RectangleF((base.Bounds.Right - (textSize.Width + 8)), ((base.Bounds.Bottom - (textSize.Height + 2))), textSize.Width + 8, textSize.Height + 2); e.Graphics.FillRectangle(this.tauBrush, rect); e.Graphics.DrawRectangles(Pens.White, new RectangleF[] {rect}); e.Graphics.DrawString(this.tauValue + "t", new Font("Symbol", 8f), Brushes.White, rect.Left + rect.Width / 2 - textSize.Width / 2, rect.Top + rect.Height / 2 - textSize.Height / 2); }

 

 

 

Thank you very much!

0 Kudos
Message 3 of 6
(4,292 Views)

Another problem I am facing if I use your solution, is that the plots are drawn over my text, see the following image;

 

 

2010-01-27_114213.jpg

 

That makes your solution unacceptable. Is there some other way to achieve this?

 

Thanks

0 Kudos
Message 4 of 6
(4,275 Views)

Nevermind my last post, I use it in AfterDrawPlotArea, which works.

 

However I still have an issue with the position of my label.

 

Thanks!

0 Kudos
Message 5 of 6
(4,274 Views)

Hi marvin,

 

Unfortunetly, I do not know if the behavior you wish to achieve will be possible with all of your constraints using the methods we have looked at.  My best suggestion is to create a label that you can position in the correct area on your form, independent of the graph.  You can monitor whether or not your graph is enabled or disabled, and from this you can change the backcolor of the label to be black or gray.  

 

 

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 6
(4,254 Views)