Custom Bars
MyGeometry.cs
using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing;
namespace ViewModelsSamples.Bars.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 += 5;
}
}
}
Razor
@page "/Bars/Custom"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
<CartesianChart
Series="@series">
</CartesianChart>
@code {
private static double[] values1 = new double[] { 2, 1, 4 };
private static double[] values2 = new double[] { 4, 3, 6 };
private static double[] values3 = new double[] { -2, 2, 1 };
private static double[] values4 = new double[] { 1, 2, 3 };
private static string starPath = LiveChartsCore.Drawing.SVGPoints.Star;
private ISeries[] series = new ISeries[]
{
new ColumnSeries<double> { Values = values1 },
new ColumnSeries<double, DiamondGeometry> { Values = values2 },
new ColumnSeries<double, VariableSVGPathGeometry> { Values = values3, GeometrySvg = starPath },
new ColumnSeries<double, ViewModelsSamples.Bars.Custom.MyGeometry> { Values = values4 }
};
}
Articles you might also find useful: