how add data labels for all markers

Jul 27, 2012 at 9:38 AM

Можно ли как-нибудь сделать, что бы рядом с точкой на графике показывалось значение функции в этой точке?? В MS Exel это называется "добавить подписи данных"

Aug 28, 2012 at 9:35 PM
Edited Aug 28, 2012 at 9:36 PM

I needed a very simple graph with only a few data points.  In order to display the value of each point I used a CustomMarker:

Public Class PointMarkerWithText : Inherits ShapeElementPointMarker
    Private _markerSize As Double = 10.0#
    Public Overrides Function CreateMarker() As UIElement
        Dim result As New StackPanel() With {.Background = New SolidColorBrush(Colors.Transparent)}

        Dim el As New Ellipse With {.Width = _markerSize, .Height = _markerSize, .Fill = Brushes.Black}

        'Add the Ellipse to the StackPanel
        result.Children.Add(el)

        If Not String.IsNullOrEmpty(ToolTipText) Then
            Dim txtPos As New TextBlock With {.Text = ToolTipText, .Margin = New Thickness(0, 6, 0, 0)}
            'Add the position text to the StackPanel
            result.Children.Add(txtPos)
        End If

        Return result
    End Function

    Public Overrides Sub SetPosition(marker As UIElement, screenPoint As Point)
        Canvas.SetLeft(marker, screenPoint.X - _markerSize / 2)
        Canvas.SetTop(marker, screenPoint.Y - _markerSize / 2)
    End Sub
End Class

I then used the marker like this:

  
            plotter.AddLineGraph(compositeDataSource, New Pen(New SolidColorBrush(Colors.Lime), 3),
                                 New PointMarkerWithText(), New PenDescription("Meas"))

 

Sep 7, 2012 at 7:48 AM

Thank you for this example, rewrite in C #, all works.

private double _markerSize = 10.0;
public override UIElement CreateMarker()
{
var result = new StackPanel() {Background = new SolidColorBrush(Colors.Transparent)};
var el = new Ellipse() { Width = _markerSize , Height = _markerSize, Fill = Brushes.Black};
result.Children.Add(el);

if (!String.IsNullOrEmpty(ToolTipText))
{
var txtPos = new TextBlock() {Text = ToolTipText, Margin = new Thickness(0,6,0,0)};
result.Children.Add(txtPos);
}
return result;
}

public override void SetPosition(UIElement marker, Point screenPoint)
{
Canvas.SetLeft(marker, screenPoint.X - _markerSize /2);
Canvas.SetTop(marker, screenPoint.Y - _markerSize / 2);
}

Oct 9, 2013 at 5:16 AM
Could you please tell me how to label data points with their ids/names (Not x or Y values). If any sample code , please post it. It will be great help.
Thanks