Custom S V G Scatter Points

This web site builds the control from code behind but you could also grab it from the toolbox, this sample also uses a ViewModel to populate the properties of the control(s) in this sample.

sample image

MyGeometry.cs

using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing;

namespace ViewModelsSamples.Scatter.Custom;

public class MyGeometry : BoundedDrawnGeometry, IDrawnElement<SkiaSharpDrawingContext>
{
    public void Draw(SkiaSharpDrawingContext context)
    {
        var paint = context.ActiveSkiaPaint;
        var canvas = context.Canvas;
        var y = Y;

        while (y < Y + Height)
        {
            canvas.DrawLine(X, y, X + Width, y, paint);
            y += 10;
        }
    }
}

Code behind

using System.Windows.Forms;
using LiveChartsCore.SkiaSharpView.WinForms;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using SkiaSharp;
using LiveChartsCore.Drawing;
using ViewModelsSamples.Scatter.Custom;

namespace WinFormsSample.Scatter.Custom;

public partial class View : UserControl
{
    public View()
    {
        InitializeComponent();
        Size = new System.Drawing.Size(50, 50);

        var values1 = Fetch();
        var values2 = Fetch();
        var values3 = Fetch();
        var pinPath = SVGPoints.Pin;

        var series = new ISeries[]
        {
            // the second type argument is the geometry to draw.
            new ScatterSeries<ObservablePoint, HeartGeometry>
            {
                Values = values1,
                Stroke = null,
                GeometrySize = 40
            },

            // the variable SVG path geometry can change the path at runtime.
            new ScatterSeries<ObservablePoint, VariableSVGPathGeometry>
            {
                Values = values2,
                GeometrySvg = pinPath,
                GeometrySize = 40
            },

            // finally you can use skiasharp to draw your own geometries.
            new ScatterSeries<ObservablePoint, MyGeometry>
            {
                Values = values3,
                GeometrySize = 40
            }
        };

        var cartesianChart = new CartesianChart
        {
            Series = series,
            Location = new System.Drawing.Point(0, 0),
            Size = new System.Drawing.Size(50, 50),
            Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom
        };

        Controls.Add(cartesianChart);
    }

    private static ObservablePoint[] Fetch()
    {
        var r = new System.Random();
        var length = 10;
        var values = new ObservablePoint[length];
        for (var i = 0; i < length; i++)
        {
            var x = r.Next(0, 20);
            var y = r.Next(0, 20);
            values[i] = new ObservablePoint(x, y);
        }
        return values;
    }
}

Articles you might also find useful:

Cartesian chart control
Scatter series properties