We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to plot Dates On X Axis of Scattered chart (C# .NET)

I am dynamically creating a Scatter Plot from an excel file. The Data points seem to come in correctly, but the X axis values are converted to numbers. (This only seems to happen with Scatter plots). Is there a way to keep the values as dates?

@mallain2323,

Can you please provide the generated presentation, desired output presentation and used sample code to us. Please also first try using latest Aspose.Slides 20.5 on your end as well.

I would like the Scatter Plot to look like the attached excel chart, however it comes out looking like the attached power poitn chart - the x axis dates are converted to numbers.

I am adding the data points to the slide using the PPIChartDataCell –
var cell1 = item.Value[0];
var cell2 = item.Value[1];
ppSeries.DataPoints.AddDataPointForScatterSeries(cell1, cell2);

I also noticed that as I add data to the second series, it mutates the first series and they end up with the same data values…
: 2020-06-22 20_55_35-Output.pptx - PowerPoint.png (4.3 KB)

2020-06-22 20_52_16-ChartExamples.xlsx - Excel.png (4.1 KB)

@mallain2323,

I have observed your requirements for creating scatter chart using date on category axis. I suggest you to please try using following example on your end.

	public static void TestScatterChart()
	{
		String path = @"C:\Aspose Data\";

		Presentation pres = new Presentation();

		ISlide slide = pres.Slides[0];

		// Creating the default chart
		IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 720, 500);

		chart.Axes.HorizontalAxis.CategoryAxisType = CategoryAxisType.Date;
		chart.Axes.HorizontalAxis.IsNumberFormatLinkedToSource = false;
		chart.Axes.HorizontalAxis.NumberFormat = "m/d/yyyy";

		// Setting Major grid lines format for value axis
		chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
		chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Black;
		chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.Width = 1;
		chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.DashStyle = LineDashStyle.DashDot;


		// Setting Major grid lines format for Category axis
		chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
		chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Black;
		chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.Width = 1;
		chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.DashStyle = LineDashStyle.Dash;



		chart.PlotArea.Width = 1;
	
		// Getting the default chart data worksheet index
		int defaultWorksheetIndex = 0;

		// Getting the chart data worksheet
		IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
		chart.ChartData.ChartDataWorkbook.Clear(defaultWorksheetIndex);

		chart.ChartData.Categories.Clear();

		
		// Delete demo series
		chart.ChartData.Series.Clear();

		// Add new series
		chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);
		chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type);

		// Take first chart series
		IChartSeries series = chart.ChartData.Series[0];

		// Add new point (1:3) there.
		series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, new DateTime(2020,05,10).ToOADate()), fact.GetCell(defaultWorksheetIndex, 2, 2, 3));

		// Add new point (2:10)
		series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, new DateTime(2020, 05, 11).ToOADate()), fact.GetCell(defaultWorksheetIndex, 3, 2, 10));

		// Edit the type of series
		series.Type = ChartType.ScatterWithMarkers;

		// Changing the chart series marker
		series.Marker.Size = 5;
		series.Marker.Symbol = MarkerStyleType.Star;

		// Take second chart series
		series = chart.ChartData.Series[1];
		series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 1), fact.GetCell(defaultWorksheetIndex, 2, 3, 2));

		// Add new point (3:1)
		series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 1), fact.GetCell(defaultWorksheetIndex, 3, 3, 6));


		// Changing the chart series marker
		series.Marker.Size = 5;
		series.Marker.Symbol = MarkerStyleType.Circle;
		series.Type = ChartType.ScatterWithMarkers;

		chart.Legend.Position = LegendPositionType.Bottom;


		pres.Save(@"C:\Aspose Data\AsposeChart_out.pptx", SaveFormat.Pptx);
	}

AsposeChart_out.zip (36.0 KB)