Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

ScatterGraph Point Label

Solved!
Go to solution

Hi to all,

I have succesfully managed to derive a CustomCursor from the XYCursor as to be able to display an icon and/or a label.

I have also managed to create a CustomGraph derived from a ScatterPlot and specify the colour of each point of the plot by entering an array of colours for each points.

 

For my CustomCurosr, it looks pretty nice because I managed to make the background colour of the label semi-transparent, and use small fonts. I would now like to be able to specify labels for the points of a ScatterGraph (in the same way). Has anyone managed to do this?

Thanks,

cdouillet

 

PS: I am happy to give my VB code for CustomCursor and CustomScatterGraph if anyone is interested.

0 Kudos
Message 1 of 4
(4,684 Views)
Solution
Accepted by topic author cdouillet

Hey,

 

Looks like you've worked quite a lot with MStudio controls. Nice!

 

I wrote some code and made graph display the labels. Here are the screenshot and the code snippet.

 

I hope this helps. If not, could you attach a screenshot of the graph presenting how the graph should look? If possible you could attach the code snippet for the custom classes. These would help us better in understanding what you intend to do with the Graph control.

 

Snapshot:

 

TransparentLabelsForDataPoints.png

 

Code Snippet:

 

Public Class MyScatterPlot
    Inherits ScatterPlot
    Protected Overrides Sub OnBeforeDraw(ByVal e As BeforeDrawXYPlotEventArgs)
        ' Let the base type do its drawing first.
        MyBase.OnBeforeDraw(e)

        ' Get the data points and mapped coordinates in pixels.
        Dim points As PointF() = MapDataPoints(e.Bounds)
        Dim xData As Double() = GetXData()
        Dim yData As Double() = GetYData()

        ' Draw label for each data point.
        For i As Integer = 0 To points.Length - 1
            DrawLabel(e.Graphics, points(i), xData(i), yData(i))
        Next
    End Sub

    Private Sub DrawLabel(ByVal g As Graphics, ByVal pointF As PointF, ByVal xData As Double, ByVal yData As Double)
        ' Setup the font, label and colors.
        Dim label As String = xData.ToString() + ", " + yData.ToString()
        Dim font As Font = New System.Drawing.Font("Verdana", 8, FontStyle.Regular)
        Dim fillColor As Color = Color.FromArgb(128, Color.Gray)
        Dim labelColor As Color = Color.White
        Dim borderColor As Color = Color.LightGray

        ' Calculate the positions of the rectangle to be drawn.
        Dim size As SizeF = g.MeasureString(label, font)
        Dim r As RectangleF = RectangleF.Empty
        r.Location = New PointF(pointF.X + 5, pointF.Y - 5 - font.Height)
        r.Size = New SizeF(size.Width, size.Height)

        ' Do the drawing here. First draw the rectangle, fill it with some color and then draw the string.
        g.FillRectangle(New SolidBrush(fillColor), r)
        g.DrawRectangle(New Pen(borderColor), r.Left, r.Top, r.Width, r.Height)
        g.DrawString(label, font, New SolidBrush(labelColor), r.Location)
    End Sub
End Class

 

 

Vijet Patankar,

National Instruments

Message 2 of 4
(4,668 Views)

Hi Vijet,

Brilliant, that works great! Thank you.

CD

0 Kudos
Message 3 of 4
(4,661 Views)

Thank you. While that works, it would serve us all better to incorporate the
functionality into the NIMS class library. Furthermore, to take the
implementation further would also benefit us all.  A couple ways  to enhance it
would be to add code to keep the values from plotting on the plot lines and
other points or labels (there should be an option and logic to prevent label overlapping ), and implement a property in the scatterplot class to
turn on or off the point-value labels.  Yes?  Does this example work if I'm plotting a bar chart?  Is there a plan to further enhance the NIMS library, please explain why or why not in
detail.  I am very concerned why this functionality is not already built in to the current version of NIMS, as the original post is 3+ years old.  It is very useful in many scenarios.  As a user of MS visual studio  and NIMS, I want a a graphing solution that has the capability to do everything I need.  Otherwise, I must maintain licensing for multiple class libraries, and suffer from discontinuity between the UI look and feel of my applications, which class or library i use depends on the module and application demands. Developers need an all-in-one package.  NI's graphing offers high-speed capabilities for working with large datasets, but when you look at summaries of those large datasets, I need extra, robust user experience capability. The high speed and robust user features can easily be built into the library without affecting the existing performance for with the NI graphing controls are notable.  Thank you, Andy Moyer. 

0 Kudos
Message 4 of 4
(3,988 Views)