Articles in this section

How to Display Datetime Data by Weeks in Blazor Charts?

This article explains how to display datetime data in weeks format in Blazor Charts.

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 the DateTime axis. This will display the datetime values with weekly intervals. An axis labels can be customized using the OnAxisLabelRender event.

The code example below demonstrates how to display datetime data in weeks format.

@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

image.png

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 features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Charts 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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied