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

Free Support Forum - aspose.com

Axes properties (DisplayUnit- NumberFormat and Title) aren't working

I am using Aspose Slides 14.2 / Visual Studio 2013 / C# / Powerpoint 2013
The following statements don’t seem to work:

chart.Axes.VerticalAxis.DisplayUnit = DisplayUnitType.Thousands; chart.Axes.VerticalAxis.NumberFormat = “#,##0.00”;
chart.Axes.VerticalAxis.Title.AddTextFrameForOverriding(
“Demo Title”);

using the following code: (using the creating a chart from scratch example, http://www.aspose.com/docs/display/slidesnet/Creating+a+Chart+from+Scratch)

// The path to the documents directory.
string dataDir = Path.GetFullPath("…/…/…/Data/");

// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
{
System.IO.Directory.CreateDirectory(dataDir);
}

//Instantiate Presentation class that represents the presentation file
using (Presentation pres = new Presentation())
{
ISlideCollection slds = pres.Slides;

//for (int i = 0; i < pres.LayoutSlides.Count; i++)
// {
//Add an empty slide to the Slides collection
var allTypes = pres.LayoutSlides.Select(item => item.LayoutType).Distinct().ToList();

var slide1 = slds.AddEmptySlide(pres.LayoutSlides.First(item => item.LayoutType == SlideLayoutType.TitleAndObject));

// slide1.Shapes.AddChart(Aspose.Slides.Charts.ChartType.StackedColumn, 0, 0, 400, 300);

var titleShape = slide1.Shapes[0];
((IAutoShape)titleShape).TextFrame.Text = “Sample Title 123”;

var objectShape = slide1.Shapes[1];

var chart = slide1.Shapes.AddChart(ChartType.ClusteredColumn, objectShape.X, objectShape.Y, objectShape.Width, objectShape.Height);
objectShape.RemovePlaceholder();
slide1.Shapes.Remove(objectShape);

chart.ChartTitle.AddTextFrameForOverriding(“Sample Title”);
chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;

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

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

//Getting the chart data worksheet
var fact = chart.ChartData.ChartDataWorkbook; //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);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “Series 2”), 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”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));

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

//Now populating series data

series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));

//Setting fill color for series
// series.Format.Fill.FillType = FillType.Solid;
// series.Format.Fill.SolidFillColor.Color = Color.Red;


//Take second chart series
series = chart.ChartData.Series[1];

//Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));



chart.Legend.Position = LegendPositionType.Bottom;
chart.Axes.VerticalAxis.DisplayUnit = DisplayUnitType.Thousands;
chart.Axes.VerticalAxis.NumberFormat = “#,##0.00”;
chart.Axes.VerticalAxis.Title.AddTextFrameForOverriding(“Demo Title”);

//Save the PPTX file to the Disk
pres.Write(dataDir + “EmptySlide.pptx”);

Hi Juri,


I have worked with the sample code shared and have observed the missing statement in the code. Please use the following sample code on your end to serve the purpsoe.

chart.Legend.Position = LegendPositionType.Bottom;
//This line is missing in your code
chart.Axes.VerticalAxis.IsNumberFormatLinkedToSource = false;
chart.Axes.VerticalAxis.DisplayUnit = DisplayUnitType.Thousands;
chart.Axes.VerticalAxis.NumberFormat = “#,##0.00”;
chart.Axes.VerticalAxis.Title.AddTextFrameForOverriding(“Demo Title”);


Many Thanks,