Aspose Slides for .Net - Horizontal Bar Chart

Hello,

How should we achieve the Horizontal Bar Chart ? Please check the screenshot attached.

Thanks,

Narayanan.

Hi Narayanan,


I have observed the requirements shared by you. Please use the following code snippet for adding the horizontal bar chart using Aspose.Slides for .NET.

public static void AddLineChart()
{

//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();

//Access first slide
SlideEx sld = pres.Slides[0];

// Add chart with default data
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredBar, 0, 0, 500, 500);

//Setting chart Title
chart.ChartTitle.Text.Text = “Sample Title”;
chart.ChartTitle.Text.CenterText = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;

//Set first series to Show Values
chart.ChartData.Series[0].Labels.ShowValue = true;

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;

//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;

//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, “Series 1”), chart.Type);
//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];

//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, -20));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, -50));

chart.CategoryAxis.DisplayUnit = DisplayUnitType.Millions;
chart.CategoryAxis.NumberFormat = “0.0%”;
chart.ValueAxis.NumberFormat = “0.0%”;
// series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));

// Save presentation with chart
pres.Write(@“D:\Aspose Data\LineChart.pptx”);


}

Many Thanks,