DateTime axis in ASP.NET MVC 3D Chart Component

9 Jan 202424 minutes to read

DateTime axis

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

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2000, 07, 11),  y= 10 },
        new ChartData { x= new DateTime(2002, 04, 07),  y= 30 },
        new ChartData { x= new DateTime(2004, 04, 06),  y= 15 },
        new ChartData { x= new DateTime(2006, 04, 30),  y= 65 },
        new ChartData { x= new DateTime(2008, 04, 08),  y= 90 },
        new ChartData { x= new DateTime(2010, 04, 08),  y= 85 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

DateTime category axis

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

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTimeCategory).Skeleton("Ed")
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2017, 12, 20), y= 21 },
        new ChartData { x= new DateTime(2017, 12, 21), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 22), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 26), y= 70 },
        new ChartData { x= new DateTime(2017, 12, 27), y= 75 },
        new ChartData { x= new DateTime(2018, 01, 02), y= 82 },
        new ChartData { x= new DateTime(2018, 01, 03), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 04), y= 54 },
        new ChartData { x= new DateTime(2018, 01, 05), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 08), y= 45 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

Range

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

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
      .Minimum(new DateTime(2000, 07, 01))
      .Maximum(new DateTime(2010, 02, 01))
      .Interval(1)
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2000, 07, 11),  y= 10 },
        new ChartData { x= new DateTime(2002, 04, 07),  y= 30 },
        new ChartData { x= new DateTime(2004, 04, 06),  y= 15 },
        new ChartData { x= new DateTime(2006, 04, 30),  y= 65 },
        new ChartData { x= new DateTime(2008, 04, 08),  y= 90 },
        new ChartData { x= new DateTime(2010, 04, 08),  y= 85 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

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
@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
      .IntervalType(Syncfusion.EJ2.Charts.IntervalType.Years)
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2000, 07, 11),  y= 10 },
        new ChartData { x= new DateTime(2002, 04, 07),  y= 30 },
        new ChartData { x= new DateTime(2004, 04, 06),  y= 15 },
        new ChartData { x= new DateTime(2006, 04, 30),  y= 65 },
        new ChartData { x= new DateTime(2008, 04, 08),  y= 90 },
        new ChartData { x= new DateTime(2010, 04, 08),  y= 85 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

Applying padding to the range

Padding can be applied to the minimum and maximum extremes of the range by using the RangePadding property. DateTime axis supports the following types of padding,

  • None
  • Round
  • Additional

DateTime - None

When the RangePadding is set to None, minimum and maximum of an axis is based on the data.

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
      .RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.None)
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2017, 12, 20), y= 21 },
        new ChartData { x= new DateTime(2017, 12, 21), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 22), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 26), y= 70 },
        new ChartData { x= new DateTime(2017, 12, 27), y= 75 },
        new ChartData { x= new DateTime(2018, 01, 02), y= 82 },
        new ChartData { x= new DateTime(2018, 01, 03), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 04), y= 54 },
        new ChartData { x= new DateTime(2018, 01, 05), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 08), y= 45 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

DateTime - Round

When the RangePadding is set to Round, minimum and maximum will be rounded to the nearest possible value, which is divisible by interval. For example, when the minimum is 15th Jan, interval is 1 and interval type is Month, then the axis minimum will be Jan 1st.

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
      .RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.Round)
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2017, 12, 20), y= 21 },
        new ChartData { x= new DateTime(2017, 12, 21), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 22), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 26), y= 70 },
        new ChartData { x= new DateTime(2017, 12, 27), y= 75 },
        new ChartData { x= new DateTime(2018, 01, 02), y= 82 },
        new ChartData { x= new DateTime(2018, 01, 03), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 04), y= 54 },
        new ChartData { x= new DateTime(2018, 01, 05), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 08), y= 45 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

DateTime - Additional

When the RangePadding is set to Additional, interval of an axis will be padded to the minimum and maximum of the axis.

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
      .RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.Additional)
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2017, 12, 20), y= 21 },
        new ChartData { x= new DateTime(2017, 12, 21), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 22), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 26), y= 70 },
        new ChartData { x= new DateTime(2017, 12, 27), y= 75 },
        new ChartData { x= new DateTime(2018, 01, 02), y= 82 },
        new ChartData { x= new DateTime(2018, 01, 03), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 04), y= 54 },
        new ChartData { x= new DateTime(2018, 01, 05), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 08), y= 45 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

Label format

The date can be formatted and parsed to all globalize format using the LabelFormat property in an axis.

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
      .LabelFormat("yMd")
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2017, 12, 20), y= 21 },
        new ChartData { x= new DateTime(2017, 12, 21), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 22), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 26), y= 70 },
        new ChartData { x= new DateTime(2017, 12, 27), y= 75 },
        new ChartData { x= new DateTime(2018, 01, 02), y= 82 },
        new ChartData { x= new DateTime(2018, 01, 03), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 04), y= 54 },
        new ChartData { x= new DateTime(2018, 01, 05), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 08), y= 45 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}

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.

@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
   .Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).  
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Add();
   })
   .PrimaryXAxis(px => 
      px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
   )
   .PrimaryYAxis(py => 
      py.LabelFormat("${value}K")
   )
   .Render())
public ActionResult Index()
{
    List<ChartData> chartData = new List<ChartData>
    {
        new ChartData { x= new DateTime(2017, 12, 20), y= 21 },
        new ChartData { x= new DateTime(2017, 12, 21), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 22), y= 24 },
        new ChartData { x= new DateTime(2017, 12, 26), y= 70 },
        new ChartData { x= new DateTime(2017, 12, 27), y= 75 },
        new ChartData { x= new DateTime(2018, 01, 02), y= 82 },
        new ChartData { x= new DateTime(2018, 01, 03), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 04), y= 54 },
        new ChartData { x= new DateTime(2018, 01, 05), y= 53 },
        new ChartData { x= new DateTime(2018, 01, 08), y= 45 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ChartData
{
    public DateTime x;
    public double y;
}