Articles in this section
Category / Section

How to use the DateTimeAxis as SecondaryAxis in WPF SfChart?

2 mins read

You can use the DateTimeAxis as SecondaryAxis by binding the ToOADate value of DateTime value to the YBindingPath property of WPF Chart series as demonstrated in the following code snippet.

 XAML:  

<chart:SfChart.SecondaryAxis>
            <chart:DateTimeAxis LabelFormat="hh:mm tt" />
 </chart:SfChart.SecondaryAxis>
 
<chart:ScatterSeries ItemsSource="{Binding Collection}"  XBindingPath="XValue" YBindingPath="YValue"/>
 

 C#:   

public class ViewModel
{
        public ObservableCollection<Model> Collection { get; set; }
 
        public ViewModel()
        {
            Collection = new ObservableCollection<Model>();
 
            DateTime date = new DateTime(2016, 1, 1);
            Collection.Add(new Model() { XValue = date.AddDays(0), DateTimeValue = date.AddMinutes(180) });
            Collection.Add(new Model() { XValue = date.AddDays(1), DateTimeValue = date.AddMinutes(360) });
            Collection.Add(new Model() { XValue = date.AddDays(2), DateTimeValue = date.AddMinutes(240) });
            Collection.Add(new Model() { XValue = date.AddDays(3), DateTimeValue = date.AddMinutes(420) });
            Collection.Add(new Model() { XValue = date.AddDays(4), DateTimeValue = date.AddMinutes(300) });
        }
    }
 
    public class Model
    {
        public DateTime XValue { get; set; }
 
        private DateTime dateTimeValue;
        public DateTime DateTimeValue
        {
            get
            {
                return dateTimeValue;
            }
            set
            {
                if (value != dateTimeValue)
                {
                    dateTimeValue = value;
 
                }
            }
        }
 
        public double YValue
        {
            get
            {
                return dateTimeValue.ToOADate();
            }
        }
 
    }

Output:

Chart with DateTime Y AXIS in WPF

Note:

The limitation of DateTimeAxis is, it does not support the series that are supported by SideBySideSeriesPlacement when using as the SecondaryAxis.

 

Conclusion

I hope you enjoyed learning about how to use the DateTimeAxis as SecondaryAxis in WPF SfChart.

You can refer to our WPF Chart feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Chart documentation to understand how to present and manipulate data.


For current customers, you can check out our WPF 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 WPF Chart and other WPF components.


If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, 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)
Please  to leave a comment
Access denied
Access denied