ScatterLineSeries Point Labels

3 posts, 0 answers
  1. Adam
    Adam avatar
    2 posts
    Member since:
    Jul 2019

    Posted 24 Jul 2019 Link to this post

    Hello,

    Is it possible to add labels to points in a ScatterLineSeries? I've been able to add labels to CategoricalDataPoints but not ScatterDataPoints. I noticed that on https://docs.telerik.com/devtools/winforms/controls/chartview/series-types/series-types there are labels for Line, Spline, Area, and SplineArea series, but not for Bar or Scatter.

    I added a custom LabelFormatting event that gets called when I use a LineSeries with CategoricalDataPoints, but it doesn't run when I use a ScatterLineSeries with ScatterDataPoints. Here's some sample code I tested (in OpenEdge) and a screenshot of my results:

    LabelFormatting method:

    METHOD PRIVATE VOID myLabelFormatting(INPUT sender AS System.Object, INPUT e AS ChartViewLabelFormattingEventArgs):
       e:LabelElement:BackColor = System.Drawing.Color:White.
       e:LabelElement:ForeColor = System.Drawing.Color:Black.
       e:LabelElement:BorderColor = System.Drawing.Color:Black.
       e:LabelElement:Font = NEW Font("Segoe Script", 12, FontStyle:Regular).
       DEFINE VARIABLE element AS CartesianLinePointElement NO-UNDO.
       MESSAGE "Casting element..." VIEW-AS ALERT-BOX.
       element = CAST(e:LabelElement:Parent, CartesianLinePointElement).
        
       DEFINE VARIABLE dataPoint AS ScatterDataPoint NO-UNDO.
       MESSAGE "Casting point..." VIEW-AS ALERT-BOX.
       dataPoint = CAST(element:DataPoint, ScatterDataPoint).
        
       e:LabelElement:Text = STRING(dataPoint:XValue) + ", " + STRING(dataPoint:YValue).
    END METHOD.

     

    Sample code:

    THIS-OBJECT:radChartView1:LabelFormatting:Subscribe(myLabelFormatting).       
     
    DEFINE VARIABLE lineSeries AS ScatterLineSeries NO-UNDO.
    lineSeries = NEW ScatterLineSeries().
    lineSeries:DataPoints:Add(NEW ScatterDataPoint(1, 10)).
    lineSeries:DataPoints:Add(NEW ScatterDataPoint(15, 15)).
    lineSeries:DataPoints:Add(NEW ScatterDataPoint(5, 20)).
    lineSeries:PointSize = NEW SizeF(8, 8).
    lineSeries:ShowLabels = TRUE.
    radChartView1:Series:Add(lineSeries).
     
    radChartView1:BackColor = System.Drawing.Color:LightGray.
    radChartView1:ShowLegend = TRUE.

     

    Thanks,

    Adam

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3713 posts

    Posted 25 Jul 2019 Link to this post

    Hello, Adam,   

    In order to show labels for the ScatterLineSeries, make sure that you set the Label for each ScatterDataPoint. Please refer to the following code snippet:

    public RadForm1()
    {
        InitializeComponent();
        this.radChartView1.LabelFormatting += radChartView1_LabelFormatting;
     
        ScatterLineSeries scatterSeries = new ScatterLineSeries();
        scatterSeries.DataPoints.Add(new ScatterDataPoint(15, 19) { Label = "15, 19" });
        scatterSeries.DataPoints.Add(new ScatterDataPoint(18, 10) { Label = "18, 10" });
        scatterSeries.DataPoints.Add(new ScatterDataPoint(13, 15) { Label = "13, 15" });
        scatterSeries.DataPoints.Add(new ScatterDataPoint(10, 8) { Label = "10, 8" });
        scatterSeries.DataPoints.Add(new ScatterDataPoint(5, 2) { Label = "5, 2" });
        scatterSeries.PointSize = new SizeF(8, 8);
        scatterSeries.ShowLabels = true;
        this.radChartView1.Series.Add(scatterSeries);
    }
     
    private void radChartView1_LabelFormatting(object sender, ChartViewLabelFormattingEventArgs e)
    {
        e.LabelElement.ForeColor = Color.Red;
    }



    Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread. Thank you for your understanding.

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Adam
    Adam avatar
    2 posts
    Member since:
    Jul 2019

    Posted 25 Jul 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you! Setting the label for each point fixed my issue.
Back to Top