I'm trying to plot a Histogram in Avalonia with C# using Livecharts2. However some empty space occurs between the columns.
How to avoid this empty space between columns?
For example in two column histogram the columns are shown as half columns on the left and right side of the screen, I want to have the columns in center of the screen.
Here's what I have done
[ObservableProperty]
private ObservableCollection<ISeries> _histogram;
[ObservableProperty]
private Axis[] _yAxes;
[ObservableProperty]
private Axis[] _xAxes;
YAxes =
[
new()
{
MinLimit = 0,
MaxLimit = Math.Round( SampleSize/(WordSize * Math.Pow(2,WordSize)) * 1.5),
SeparatorsPaint = new SolidColorPaint(new SKColor(200, 200, 200)),
TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),
}
];
XAxes =
[
new()
{
MinLimit = 0,
MaxLimit = Math.Round( Math.Pow(2,WordSize)-1),
SeparatorsPaint = new SolidColorPaint(new SKColor(200, 200, 200)),
TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),
}
];
var colors = new SolidColorPaint[]
{
new(SKColors.Red),
new(SKColors.Green),
new(SKColors.Blue),
new(SKColors.Yellow),
new(SKColors.Cyan),
new(SKColors.Magenta),
new(SKColors.AliceBlue),
new(SKColors.AntiqueWhite),
new(SKColors.BlueViolet),
new(SKColors.Brown)
};
Histogram =
[
new ColumnSeries<int>
{
Values = _data;
Name = "Histogram",
}
.OnPointMeasured(point =>
{
if (point.Visual is null) return;
var paint = colors[point.Index % colors.Length];
point.Visual.Fill = paint;
})
];
<avalonia:CartesianChart
Grid.Row="1"
EasingFunction="{x:Null}"
Series="{Binding Histogram}"
XAxes="{Binding XAxes}"
YAxes="{Binding YAxes}"
ZoomMode="None"
/>
Thanks to @jdweng comment I can expand the view area by setting the XAxes.MinLimit to less than the actual min limit of x values and setting the XAxes.MaxLimit to more then the actual limit of x values.
a Better way is to remove XAxes limits totally and leave them to be decided by livechart
And to remove free x points between actual data setting XAxes.Lables will solve this problem.