How to return double value from datetime value through IChartSeriesModel in WinForms Chart?
The IChartSeriesModel can convert DateTime values to double values using the ToOADate method provided by DateTime. This is particularly useful when working with WinForms Chart that require numerical data for plotting.
// Set X-axis to double (OADate)
this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.Double;
this.chartControl1.PrimaryXAxis.Range = new MinMaxInfo(36000, 39800, 400);
ChartSeries chartSeries1 = new ChartSeries("Sales");
chartSeries1.Type = ChartSeriesType.Line;
// Add points using OADate
foreach (var data in dataSource)
{
chartSeries1.Points.Add(data.Date.ToOADate(), data.YValue);
}
this.chartControl1.Series.Add(chartSeries1);
Dim viewModel As BrandViewModel = New BrandViewModel()
Dim ChartSeries1 As ChartSeries = New ChartSeries("Sales")
'Set X-axis to double (OADate)
lineChart.PrimaryYAxis.ValueType = ChartValueType.Double
lineChart.PrimaryXAxis.ValueType = ChartValueType.Double
lineChart.PrimaryXAxis.Range = New MinMaxInfo(36000, 39800, 400)
ChartSeries1.Type = ChartSeriesType.Line
'Add points using OADate
For Each item In viewModel.PlantDetails1
ChartSeries1.Points.Add(item.Date1.ToOADate(), item.YValue)
Next
lineChart.Series.Add(ChartSeries1)
Conclusion
I hope you enjoyed learning about how to return DateTime value through IChartSeriesModel in WinForms Chart.
You can refer to our WinForms Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms Chart examples to understand how to create and manipulate data.
For current customers, you can check out our 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 other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!