This is a migrated thread and some comments may be shown as answers.

Custom shape with line for ScatterLineSeries point

1 Answer 8 Views
This is a migrated thread and some comments may be shown as answers.
Valery
Top achievements
Rank 1
Veteran
Valery asked on 14 Apr 2020, 06:47 AM

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

 

1 Answer, 1 is accepted

Sort by
0
Nadya
Telerik team
answered on 15 Apr 2020, 01:30 PM

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.
Asked by
Valery
Top achievements
Rank 1
Veteran
Answers by
Nadya
Telerik team
Share this question
or