DateTimeAxis internal is not working.

How to show X axis  values as shown in below image.

I have tried with
1. Minimum and Maximum
2. Delta values.

DateTimeAxis primaryAxis = new DateTimeAxis()
            {
                Interval = 3,
                IntervalType = DateTimeIntervalType.Hours,
                ShowMajorGridLines = false,
                //EdgeLabelsVisibilityMode = EdgeLabelsVisibilityMode.AlwaysVisible,
            };

            primaryAxis.SetBinding(DateTimeAxis.MinimumProperty, new Binding("UsualAndMeasuredMinimum"));
            primaryAxis.SetBinding(DateTimeAxis.MaximumProperty, new Binding("UsualAndMeasuredMaximum"));

            primaryAxis.MajorTickStyle.TickSize = 7;
            primaryAxis.MajorTickStyle.StrokeWidth = 1;
            primaryAxis.MajorTickStyle.StrokeColor = Color.LightGray;

           primaryAxis.LabelStyle = new ChartAxisLabelStyle { LabelFormat = "HH:mm" };

Please help me here....


1 Reply 1 reply marked as answer

YP Yuvaraj Palanisamy Syncfusion Team June 15, 2021 07:52 AM UTC

Hi Chaitanya, 
 
Greetings from Syncfusion. 
 
We have analyzed your query “DateTime axis with Minimum, Maximum and Interval” and we have achieved your requirement as like in the provided image with the help of binding Minimum, Interval and Maximum property of DateTimeAxis. Please find the code example below. 
 
CodeSnippet: [XAML] 
<chart:SfChart.PrimaryAxis> 
    <chart:DateTimeAxis x:Name="dateTimeAxis" 
        Interval="3" 
        IntervalType="Hours" 
        Minimum="{Binding MinimumDate}" 
        Maximum="{Binding MaximumDate}"> 
 
        <chart:DateTimeAxis.LabelStyle> 
            <chart:ChartAxisLabelStyle LabelFormat="HH:mm"  
                                       TextColor="Black" /> 
        </chart:DateTimeAxis.LabelStyle> 
    </chart:DateTimeAxis> 
</chart:SfChart.PrimaryAxis> 
 
C#: 
DateTimeAxis dateTimeAxis = new DateTimeAxis(); 
dateTimeAxis.Interval = 3; 
dateTimeAxis.IntervalType = DateTimeIntervalType.Hours; 
dateTimeAxis.SetBinding(DateTimeAxis.MinimumProperty, new Binding("MinimumDate")); 
dateTimeAxis.SetBinding(DateTimeAxis.MaximumProperty, new Binding("MaximumDate")); 
dateTimeAxis.LabelStyle = new ChartAxisLabelStyle() { LabelFormat = "HH:mm" }; 
chart.PrimaryAxis = dateTimeAxis; 
 
ViewModel.cs 
public DateTime MinimumDate { get; set; } 
 
public DateTime MaximumDate { get; set; } 
 
public ViewModel() 
{ 
 
    DateTime dateTime = new DateTime(2021, 01, 01, 01, 01, 0); 
 
    MinimumDate = dateTime.AddHours(-1); 
    MaximumDate = dateTime.AddHours(20); 
} 
 
Also, we have attached the sample for your reference. Please find the sample from the below link. 
 
  
Output: 
 
For more details, please refer the below ug document 
 
 
Please let us know if you have any concern. 
 
Regards, 
Yuvaraj. 


Marked as answer
Loader.
Up arrow icon