Search results

DateTime and DateTimeCategory Axis

DateTime Axis

 Date time axis uses date time scale and displays the date time values as axis labels in the specified format.

datetime.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>
  
  <ChartSeriesCollection>
     <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
     </ChartSeries>
  </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

DateTime Axis

DateTimeCategory Axis

Date-time category axis is used to display the date-time values with non-linear intervals. For example, the business days alone can been depicted in a week here.

dateCategory.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis Skeleton="Ed" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>

   <ChartSeriesCollection>
     <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
     </ChartSeries>
   </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

Range

Range for an axis, will be calculated automatically based on the provided data, you can also customize the range of the axis using Minimum, Maximum and Interval property of the axis.

range.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis Interval="1" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>

   <ChartSeriesCollection>
      <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
      </ChartSeries>
   </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

Range

Interval Customization

Date time intervals can be customized by using the Interval and IntervalType properties of the axis. For example, when you set Interval as 2 and IntervalType as years, it considers 2 years as Interval. DateTime axis supports following Interval types,

  • Auto
  • Years
  • Months
  • Days
  • Hours
  • Minutes
  • Seconds
interval.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis IntervalType="IntervalType.Years" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>

   <ChartSeriesCollection>
     <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
     </ChartSeries>
   </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

Applying Padding to the Range

Padding can be applied to the Minimum and Maximum extremes of the range by using the RangePadding property. Date time axis supports the following types of padding,

  • None
  • Round
  • Additional

DateTime - None

When the RangePadding is set to None, Minimum and Maximum of the axis is based on the data.

none.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis RangePadding="ChartRangePadding.None" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>

   <ChartSeriesCollection>
      <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
      </ChartSeries>
  </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

DateTime - Round

When the RangePadding is set to Round, Minimum and Maximum will be rounded to the nearest possible value divisible by Interval. For example, when the Minimum is 15th Jan, Interval is 1 and the Interval type is ‘month’, then the axis Minimum will be Jan 1st.

round.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
  <ChartPrimaryXAxis RangePadding="ChartRangePadding.Round" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
  </ChartPrimaryXAxis>

  <ChartSeriesCollection>
    <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
    </ChartSeries>
  </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

DateTime - Additional

When the RangePadding is set to Additional, Interval of an axis will be padded to the Minimum and Maximum of the axis.

additional.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis RangePadding="ChartRangePadding.Additional" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>
  
   <ChartSeriesCollection>
      <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
      </ChartSeries>
  </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

Label Format

You can format and parse the date to all globalize format using LabelFormat property in an axis.

label-format.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
  <ChartPrimaryXAxis LabelFormat="yMd" ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
  </ChartPrimaryXAxis>

  <ChartSeriesCollection>
    <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
    </ChartSeries>
  </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

The following table describes the result of applying some common date time formats to the labelFormat property

Label Value Label Format Property Value Result Description
new Date(2000, 03, 10) EEEE Monday The Date is displayed in day format
new Date(2000, 03, 10) yMd 04/10/2000 The Date is displayed in month/date/year format
new Date(2000, 03, 10) MMM Apr The Shorthand month for the date is displayed
new Date(2000, 03, 10) hm 12:00 AM Time of the date value is displayed as label
new Date(2000, 03, 10) hms 12:00:00 AM The Label is displayed in hours:minutes:seconds format

Custom Label Format

Axis also supports custom label format using placeholder like {value}°C, in which the value represent the axis label e.g 20°C.

custom.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
   <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime">
   </ChartPrimaryXAxis>
  
   <ChartPrimaryYAxis LabelFormat="${value}K"></ChartPrimaryYAxis>
  
   <ChartSeriesCollection>
     <ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="ChartSeriesType.Line">
     </ChartSeries>
   </ChartSeriesCollection>
</EjsChart>

@code{
public class ChartData
  {
    public DateTime XValue;
    public double YValue;
  }
public List<ChartData> WeatherReports =  new List<ChartData> 
  {
     new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
     new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
     new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
     new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
   };
}

See Also