Need help getting Line Chart X Axis to Date format

I'm trying to create a line chart with XlsIO providing data directly from my code.

I cannot make my X-Axis be a date axis like I can on excel.

Here is an illustration of my issue:




var application = xl.Excel;
var workbook = application.Workbooks.Create(0);

var chart = workbook.Charts.Add();
chart.ChartType = ExcelChartType.Line;
chart.PrimaryCategoryAxis.CategoryType = ExcelCategoryType.Automatic;
chart.PrimaryCategoryAxis.NumberFormat = "dd.MM.yyyy";
chart.PrimaryCategoryAxis.AutoTickLabelSpacing = true;
chart.PrimaryCategoryAxis.MajorUnitScale = ExcelChartBaseUnit.Month;
chart.PrimaryCategoryAxis.MajorUnit = 6;
chart.PrimaryCategoryAxis.EnteredDirectlyCategoryLabels = fundTimeseries.Items.Select(x => (object)x.Date.ToDateTime()).ToArray();

var fundSerie = chart.Series.Add(ExcelChartType.Line);
fundSerie.EnteredDirectlyValues = fundTimeseries.Items.Select(x => (object)x.Value).ToArray();

fundSerie.SerieFormat.LineProperties.LineColor = Color.FromArgb(1, 0, 89, 80);

var bmkSerie = chart.Series.Add(ExcelChartType.Line);
bmkSerie.EnteredDirectlyValues = benchmarkTimeseries.Items.Select(x => (object)x.Value).ToArray();


Any suggestions?





1 Reply

MA MohamedyusufKhan AhamedMusthafa Syncfusion Team July 20, 2023 10:42 AM UTC

Hi Richard,


We have tried a simple sample at our end but are unable to reproduce the reported issue. This sample can be downloaded from the link below.


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Line_Chart-1403353852


Kindly modify and share with us the issue reproducing sample along with the input and output Excel document. Also, please confirm the Syncfusion XlsIO version and platform you are using at your end to investigate the query.


Regards,

Mohamed Yusuf Khan.


Loader.
Up arrow icon