Custom shape with line for ScatterLineSeries point

2 posts, 0 answers
  1. Valery
    Valery avatar
    65 posts
    Member since:
    May 2011

    Posted 14 Apr Link to this post

    I created custom shape

        public class LineShape : ElementShape
        {
            public override GraphicsPath CreatePath(Rectangle bounds)
            {
                var path = new GraphicsPath();
                path.AddLine(bounds.X, bounds.Y + 1.0f, bounds.X + bounds.Width, bounds.Y + bounds.Height);
                return path;
            }
        }

    When I add a ScatterSeries, then assigned Shape = LineShape. But these points are not drawn on the chart!!!

    However, if I add an event

            private void LegendElement_VisualItemCreating(object sender, LegendItemElementCreatingEventArgs e)
            {
                e.ItemElement = new LegendItemElement(e.LegendItem);
                if (!(e.LegendItem.Element is ScatterSeries seria)) return;
                e.ItemElement.MarkerElement.Shape = seria.Shape;
            }

    then LineShape drawn in the legend

     

  2. Nadya
    Admin
    Nadya avatar
    389 posts

    Posted 15 Apr Link to this post

    Hello Valery,

    Thank you for providing the custom ElementShape. In order to use it as a custom shape for the ScatterPointElements that represent the data points in ScatterSeria, you should set the ScatterPointElement.BorderWidth property. Please refer to the following code snippet:

    public ScatterSeria()
            {
                InitializeComponent();
    
                ScatterSeries scatterSeries = new ScatterSeries();
                scatterSeries.DataPoints.Add(new ScatterDataPoint(15, 19));
                scatterSeries.DataPoints.Add(new ScatterDataPoint(18, 10));
                scatterSeries.DataPoints.Add(new ScatterDataPoint(13, 15));
                scatterSeries.DataPoints.Add(new ScatterDataPoint(10, 8));
                scatterSeries.DataPoints.Add(new ScatterDataPoint(5, 12));
                scatterSeries.PointSize = new SizeF(10, 10);
                scatterSeries.BorderColor = Color.Red;
    
                foreach (ScatterPointElement point in scatterSeries.Children)
                {
                    point.BorderWidth = 1;
                }
                scatterSeries.Shape = new LineShape();
                this.radChartView1.Series.Add(scatterSeries);

    I hope this helps. Should you have other questions I will be glad to help.

    Regards,
    Nadya
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top