Sets the width of the axis in pixels. If not specified, the width is calculated automatically. Setting a fixed width can help reduce unnecessary spacing when using multiple Y-axes.

This commit is contained in:
Wim Soetens
2026-07-03 12:30:33 +02:00
parent 233596fd69
commit ae4ece82f2
4 changed files with 17 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Globalization;
using Microsoft.AspNetCore.Components;
namespace Radzen.Blazor
{
@@ -82,6 +82,12 @@ namespace Radzen.Blazor
[Parameter]
public int TickDistance { get; set; } = 100;
/// <summary>
/// Gets or sets the width of the axis in pixels. If not set, the width is calculated automatically based on the axis content.
/// </summary>
[Parameter]
public int? Width { get; set; }
/// <summary>
/// Specifies the minimum value of the axis.
/// </summary>
@@ -141,7 +147,7 @@ namespace Radzen.Blazor
[Parameter]
public object? CrossesAt { get; set; }
/// <summary>
/// <summary>
/// Specifies the label rotation angle in degrees. Set to <c>null</c> by default which means no rotation is applied. Has higher precedence than <see cref="LabelAutoRotation"/>.
/// </summary>
[Parameter]

View File

@@ -3,7 +3,7 @@
@inherits AxisBase
<CascadingValue Value="@this">
@ChildContent
@ChildContent
</CascadingValue>
@code {
[Parameter]
@@ -21,7 +21,7 @@
}
else
{
return AxisMeasurer.YAxis(chart.ValueScale, chart.ValueAxis, Title);
return AxisMeasurer.YAxis(chart.ValueScale, this, Title);
}
}

View File

@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Components;
using System;
using System.ComponentModel;
namespace Radzen.Blazor.Rendering
{
@@ -22,6 +20,12 @@ namespace Radzen.Blazor.Rendering
ArgumentNullException.ThrowIfNull(axis);
ArgumentNullException.ThrowIfNull(title);
//We can use the axis width if it is set, otherwise we need to calculate the width based on the ticks and title
if (axis.Width.HasValue)
{
return axis.Width.Value;
}
var ticks = scale.Ticks(axis.TickDistance);
double length = 0;

View File

@@ -13,7 +13,7 @@
<RadzenAxisTitle Text="Revenue ($)" />
<RadzenGridLines Visible="true" />
</RadzenValueAxis>
<RadzenValueAxis Name="orders">
<RadzenValueAxis Width="50" Name="orders">
<RadzenAxisTitle Text="Order Count" />
</RadzenValueAxis>
<RadzenLegend Position="LegendPosition.Bottom" />