Hi, here is some example code that reproduces the issue. I am using Aspose.Slides for .NET 4.0 17.8. I have tried two ways to try and achieve what I want but both give different values. I have attached the output plus what I am trying to achieve.
Aspose Example.zip (34.2 KB)
Thanks.
//create PPT document.
Presentation presentation = new Presentation();
// Get slides from presentation.
ISlideCollection slides = presentation.Slides;
// Set slide to first slide.
ISlide slide = presentation.Slides[0];
// Add a clustered bar chart.
IChart chart = slide.Shapes.AddChart(ChartType.ClusteredBar, 100, 100, 350, 400);
// Clear the current example data from the chart
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
chart.ChartData.ChartDataWorkbook.Clear(0);
// Create dummy data
string[] prods = new string[] {"Product 1", "Product 2", "Product 3", "Product 4", "Product 5"};
double[] values = new double[] { 5.4, 6.5, 5.2, 6.4, 5.2 };
int[] colours = new int[] {6740479, 9359529, 11892015, 10498160, 8696052};
// Set the default chart worksheet index
int defaultWorksheetIndex = 0;
// Get the chart data worksheet
IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook;
// Add a series (Mean)
IChartSeries series = chart.ChartData.Series.Add(workbook.GetCell(defaultWorksheetIndex, 0, 1, "Mean"), chart.Type);
IChartDataPoint point;
// Add the data to the workbook
for (int i = 0; i < prods.Length; i++)
{
chart.ChartData.Categories.Add(workbook.GetCell(defaultWorksheetIndex, i + 1, 0, prods[i]));
series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, i + 1, 1, values[i]));
// Colour the bars
Color color = From0BGR(colours[i]);
point = series.DataPoints[i];
point.Format.Fill.FillType = FillType.Solid;
point.Format.Fill.SolidFillColor.Color = color;
}
// Add data labels
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
// Tidy up the chart
// Remove legend
chart.HasLegend = false;
// Remove vertical axis labels
chart.Axes.VerticalAxis.TickLabelPosition = TickLabelPositionType.None;
// Remove gridlines
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
// Set bar widths
series.ParentSeriesGroup.GapWidth = 20;
// Set plot area to top of chart
chart.PlotArea.Height = 1;
// Get plot area height
chart.ValidateChartLayout();
float xAxisLocation = chart.PlotArea.ActualY;
// Calculate required height
float height = chart.Height - xAxisLocation;
// Add box next to axis
IShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 5, 100, 95, height);
// Try .ActualHeight instead
chart.ValidateChartLayout();
height = chart.PlotArea.ActualHeight;
// Add another shape
IShape shape2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 5, 100, 95, height);
// Save presentation.
string filePath = System.IO.Path.GetTempPath() + "/horizontal_bar.pptx";
presentation.Save(filePath, SaveFormat.Pptx);
// Open the file
System.Diagnostics.Process.Start(filePath);