How to Show Axis Labels at Specific DateTime Values in Blazor Charts?
This article explains how to display axis labels at specified values on a datetime axis in Blazor Charts.
Display Axis Labels at Specified Values on a DateTime Axis
Blazor Charts provides an option to display axis labels at specified values on a datetime axis. This can be achieved by setting the Interval and IntervalType properties on the datetime axis.
The following code example demonstrates how to display axis labels at specified values on a datetime axis.
Index.razor
@using Syncfusion.Blazor.Charts
<SfChart Title="Heart Rate at Rest">
<ChartPrimaryXAxis EdgeLabelPlacement="EdgeLabelPlacement.Shift" LabelFormat="h:mm tt" Interval=1 IntervalType="Syncfusion.Blazor.Charts.IntervalType.Hours" ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime">
</ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries Name="Heart Rate at Rest" DataSource="@Data" Width=2 XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Line">
<ChartMarker Visible=true></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
<ChartTooltipSettings Enable=true></ChartTooltipSettings>
<ChartLegendSettings Visible=false></ChartLegendSettings>
</SfChart>
@code {
public class ChartData
{
public DateTime X { get; set; }
public double YValue { get; set; }
}
public List<ChartData> Data = new List<ChartData>
{
new ChartData { X= new DateTime(2012, 01, 01, 1, 00, 00), YValue= 46 },
new ChartData { X= new DateTime(2012, 01, 01, 2, 00, 00), YValue= 27 },
new ChartData { X= new DateTime(2012, 01, 01, 3, 00, 00), YValue= 36 },
new ChartData { X= new DateTime(2012, 01, 01, 4, 00, 00), YValue= 23 },
new ChartData { X= new DateTime(2012, 01, 01, 5, 00, 00), YValue= 38 },
new ChartData { X= new DateTime(2012, 01, 01, 6, 00, 00), YValue= 26 },
new ChartData { X= new DateTime(2012, 01, 01, 7, 00, 00), YValue= 32 },
new ChartData { X= new DateTime(2012, 01, 01, 8, 00, 00), YValue= 20 },
};
}
The following screenshot illustrates the output of the code snippet.
Live sample for displaying axis labels at specified values on a datetime axis
Conclusion:
We hope you enjoyed learning how to show axis labels at specific datetime values in Blazor Charts.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Charts and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!