Which Property does DateTimeAxis read from.

Hi,

My chart is working fine, but I am unable to figure out how does the chart decide which property to use from my class for the DateTimeAxis. Let me explain.

I have set the series.ItemsSource to a Collection of Custom Objects. Each object has 4 properties ID, Value, RecordDate, ModifiedDate. My question is that when I bind the collection to the chart, and make X Axis to be a DateTimeAxis, how does the chart figure out if it should use the RecordDate or the ModifiedDate on the X-Axis. My code is as follows:.

             chart = new SfChart();
            chart.VerticalOptions = LayoutOptions.FillAndExpand;
           
            //xaxis
            //https://www.syncfusion.com/forums/131901/date-format-datetimeaxis
            DateTimeAxis dateTimeAxis = new DateTimeAxis();
            dateTimeAxis.Title.Text = "";
            dateTimeAxis.LabelStyle.LabelFormat = "dd-MMM-yy";
            dateTimeAxis.LabelRotationAngle = 90;
            chart.PrimaryAxis = dateTimeAxis;
            chart.PrimaryAxis.IsVisible = true;
 

            //Initializing secondary Axis
            NumericalAxis secondaryAxis = new NumericalAxis();   
            series.ItemsSource = customDataList;           
            chart.SecondaryAxis = secondaryAxis;
            chart.SecondaryAxis.IsVisible = true;


 
            series = new LineSeries();          
            series.XBindingPath = "ID";
            series.YBindingPath = "Number";

            series.DataMarker = new ChartDataMarker();
            series.DataMarker.ShowMarker = true;
            series.DataMarker.ShowLabel = true;

            series.EnableTooltip = true;
           
            chart.Series.Add(series);

Tx

1 Reply

DD Devakumar Dhanapoosanam Syncfusion Team February 20, 2020 07:02 AM UTC

Hi Dev clinicea, 
 
Greetings from Syncfusion. 
 
Query: How does the chart figure out if it should use the RecordDate or the ModifiedDate on the X-Axis 
 
In order to have a desired model property values in X axis, we have to set that into XBindingPath when using collection of custom objects (ItemsSource) in SfChart as per in below code snippet 
 
CodeSnippet [C#]: 
LineSeries series = new LineSeries(); 
series.ItemsSource = customDataList; 
series.XBindingPath = "RecordDate"; //set your model for XAxis in the XBindingPath value here 
series.YBindingPath = "Value"; // your model for YAxis in the YBindingPath value here 
 
To know more about this, 
 
 
Please let us know if you need any further assistance and please feel free to contact us. 
 
Regards, 
Devakumar D  


Loader.
Up arrow icon