Chart 0 at beginning and end of x-axis

This commit is contained in:
Vladimir Enchev
2026-01-15 18:28:39 +02:00
parent 98e8393d14
commit 669ad421d9
2 changed files with 14 additions and 3 deletions

View File

@@ -10,7 +10,18 @@ namespace Radzen.Blazor
public override object Value(double value)
{
return Data?.ElementAtOrDefault(Convert.ToInt32(value)) ?? default(int);
if (Data == null)
{
return default!;
}
var index = Convert.ToInt32(value);
if (index < 0 || index >= Data.Count)
{
return default!;
}
return Data[index];
}
public override (double Start, double End, double Step) Ticks(int distance)

View File

@@ -6,10 +6,10 @@
<Line class="rz-line" X1="@x1" Y1="@y1" X2="@x2" Y2="@y1" Stroke="@(XAxis?.Stroke)" StrokeWidth="@(XAxis?.StrokeWidth ?? 0)" LineType="@(XAxis?.LineType ?? LineType.Solid)" />
@for (var idx = start; idx <= end; idx += step)
{
var value = Chart?.CategoryScale?.Value((double)idx) ?? 0;
var value = Chart?.CategoryScale?.Value((double)idx);
var x = Chart?.CategoryScale?.Scale((double)idx, true) ?? 0;
var text = XAxis != null && Chart?.CategoryScale != null ? XAxis.Format(Chart.CategoryScale, value) : "";
var text = value != null && XAxis != null && Chart?.CategoryScale != null ? XAxis.Format(Chart.CategoryScale, value) : "";
if (XAxis?.Ticks?.Template != null)
{