How to Display Datetime Data by Weeks in Blazor Charts?
This article explains how to display datetime data in weeks.
Displaying datetime data by weeks
Blazor Charts provides an option to display the datetime axis labels in weeks using Interval and IntervalType.
This can be achieved by specifying the Interval as 7 and IntervalType as Days in DateTime axis. This will display the datetime values in weeks difference. An axis labels can be customized using OnAxisLabelRender event.
The below code example demonstrates how to display datetime data in weeks.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartEvents OnAxisLabelRender="LabelRenderEvt"></ChartEvents>
<ChartPrimaryXAxis IntervalType="Syncfusion.Blazor.Charts.IntervalType.Days" Interval=7 ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime">
</ChartPrimaryXAxis>
</SfChart>
@code {
String[] stringarr = new String[] { "Week1", "Week2", "Week3", "Week4" };
public int count = 0;
public void LabelRenderEvt(Syncfusion.Blazor.Charts.AxisLabelRenderEventArgs args)
{
if (count > 3)
count = 0;
if(args.Axis.Name == "PrimaryXAxis")
{
args.Text = stringarr[count];
count++;
}
}
public class ChartData
{
public DateTime XValue { get; set; }
public double YValue { get; set; }
}
public List<ChartData> WeatherReports = new List<ChartData>
{
new ChartData { XValue = new DateTime(2005, 01, 05), YValue = 21 },
new ChartData { XValue = new DateTime(2005, 01, 10), YValue = 24 },
//...
};
}
The following screenshot illustrates the output of the code snippet.
Output
Live Sample for Displaying Weeks
Conclusion:
We hope you found this guide helpful in learning How to display datetime data by weeks in Blazor Charts. For more features, visit our [Blazor Charts feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our [Blazor Charts example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries 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!