Hello,
Sorry for the delay. I had to make a dummy program as the original is spread out over a multitude of methods. In the process I made a few more discoveries. It seems like the ppt actually generates properly, it is the getThumbnail() method that is somehow changing the properties of the shape.
Result taken from pptx.png (79.0 KB)
Chart GetThumbnail Save.png (26.5 KB)
Here’s the code, as requested:
static void Main(string[] args)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
var stream = File.OpenRead("data0.csv");
IExcelDataReader reader = ExcelDataReader.ExcelReaderFactory.CreateCsvReader(stream);
var result = reader.AsDataSet();
List<DateTime> dates = result.Tables[0].AsEnumerable().Select(
r => DateTime.Parse(r.Field<string>(0), new CultureInfo("en-US"))
).ToList();
List<double> values = result.Tables[0].AsEnumerable().Select(r => Double.Parse(r.Field<string>(1))).ToList();
Presentation presentation = new Presentation();
ISlide slide = presentation.Slides[0];
IChart chart = slide.Shapes.AddChart(ChartType.Line, 10, 50, 900, 1200);
IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
// Y Axis Styling
chart.Axes.VerticalAxis.IsAutomaticMinValue = false;
chart.Axes.VerticalAxis.MinValue = Math.Floor(values.Min());
// X Axis Syling
chart.Axes.HorizontalAxis.IsNumberFormatLinkedToSource = false;
chart.Axes.HorizontalAxis.CategoryAxisType = CategoryAxisType.Date;
chart.Axes.HorizontalAxis.IsAutomaticMajorUnit = false;
chart.Axes.HorizontalAxis.MajorUnit = 3;
chart.Axes.HorizontalAxis.MajorUnitScale = TimeUnitType.Months;
chart.Axes.HorizontalAxis.BaseUnitScale = TimeUnitType.Days;
chart.Axes.HorizontalAxis.NumberFormat = "dd-MMM-yy";
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
// Populate Values
chart.ChartData.Series.Add(wb.GetCell(0, 0, 0, "Values"), chart.Type);
int row = 1;
foreach (double value in values)
{
IChartDataCell cell = wb.GetCell(0, row, 0, value);
chart.ChartData.Series[0].DataPoints.AddDataPointForLineSeries(cell);
row++;
}
// Populate Dates
foreach (DateTime date in dates)
chart.ChartData.Categories.Add(date.ToOADate());
// General Styling
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
chart.FillFormat.FillType = FillType.Solid;
chart.FillFormat.SolidFillColor.Color = Color.White;
chart.Legend.Position = LegendPositionType.Bottom;
// Saving
presentation.Save("test.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
Bitmap chartBitmap = chart.GetThumbnail(ShapeThumbnailBounds.Shape, 1, 1);
chartBitmap.Save("image.png", ImageFormat.Png);
}