Hello,
IPresentation pptxDoc = Presentation.Create(); // Create an instance of Presentation Renderer for converting chart to image pptxDoc.PresentationRenderer = new PresentationRenderer(); //Adds a blank slide to the Presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Adds chart to the slide with position and size IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500); //Specifies the chart title chart.ChartTitle = "Sales Analysis"; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Stacked; //Sets chart data - Row1 chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); //Sets chart data - Row2 chart.ChartData.SetValue(2, 1, 2010); chart.ChartData.SetValue(2, 2, 900); chart.ChartData.SetValue(2, 3, 800); //Sets chart data - Row3 chart.ChartData.SetValue(3, 1, 2011); chart.ChartData.SetValue(3, 2, 800); chart.ChartData.SetValue(3, 3, 700); //Sets chart data - Row4 chart.ChartData.SetValue(4, 1, 2012); chart.ChartData.SetValue(4, 2, 700); chart.ChartData.SetValue(4, 3, 600); //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1]; //Creates a new chart series with the name IOfficeChartSerie seriesJan = chart.Series.Add("Jan"); //Sets the data range of chart series – start row, start column, end row, end column seriesJan.Values = chart.ChartData[2, 2, 4, 2]; //Creates a new chart series with the name IOfficeChartSerie seriesFeb = chart.Series.Add("Feb"); //Sets the data range of chart series – start row, start column, end row, end column seriesFeb.Values = chart.ChartData[2, 3, 4, 3]; //Set the primary axis for the serie seriesFeb.UsePrimaryAxis = false; using (var stream = new MemoryStream()) { pptxDoc.PresentationRenderer.ConvertToImage(chart, stream); slide.Shapes.AddPicture(stream, 100, 10, 700, 500); } FileStream outputStream = new FileStream("Sample.pptx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); pptxDoc.Save(outputStream); pptxDoc.Close(); outputStream.Flush(); outputStream.Dispose(); |
I'm using the latest Syncfusion.Presentation.Net.Core and Syncfusion.PresentationRenderer.Net.Core nuget package versions (v19.1.0.57)
Thanks in advance!
//Set the serie format of chart
serieFeb.SerieFormat.CommonSerieOptions.Overlap = 100;
serieFeb.SerieFormat.CommonSerieOptions.GapWidth= 50;|
|
|
|