Free Support Forum - aspose.com

Charting control

Hi,

How to create a normal column chart with min/max x axis value and y axis value.

Thanks.

Hi,


I have observed the requirement shared by you but unfortunately have not been able to completely understand that. Can you please share the details about your requirement. I also like to share that Aspose.Slides for .NET allows you to create the charts. Please visit this documentation link for your kind reference.

Many Thanks,

Hi,

I did refer the same link today morning. But I am not able do the following things:

1.set min/max values for x-axis and y axis

2.create secondary y axis.

Hi,


I have observed your requirements. I like to share that on X-axis (Category Axis) the category is plotted and series is plotted on Y-axis( Value axis). Can you please elaborate what do you mean by setting min/max values for x-axis and y-axis. The x-axis only contain the category names. Secondly, in my humble opinion, setting min/max values for value axis is also unavailable in PowerPoint. Can you please share the way in the form of snapshot for setting min/max values for the axis in PowerPoint and I will try to implement the same on my end using Aspose.Slides. Please share information in this regard so that I may help you further.

For your second point related to plotting series values on secondary axis, please use following code snippet as example.

PresentationEx pres;
pres = new PresentationEx();
SlideEx sld = pres.Slides[0];
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 500, 500);
chart.ChartTitle.Text.Text = “Sample Title”;
chart.ChartTitle.Text.CenterText = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = false;
chart.HasLegend = false;
chart.ChartData.Series[0].Labels.ShowValue = true;

chart.SecondCategoryAxis.IsVisible = true;

int defaultWorksheetIndex = 0;
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, “1”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “2”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, “3”), chart.Type);
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “Age”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “Gender”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “Status”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 4, 0, “Nationality”));
chart.GapDepth = 200;
//chart.GapWidth = 50 I need to be able to do something similar to this code

ChartSeriesEx series = chart.ChartData.Series[0];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(32, 202, 250);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 40));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 64));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 1, 1));
series.PlotOnSecondAxis = true;

series = chart.ChartData.Series[1];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(0, 122, 171);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 4));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 19));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 2, 25));
series.PlotOnSecondAxis = true;

series = chart.ChartData.Series[2];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(0, 136, 188);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 3));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 17));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 0));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 2, 63));

series.PlotOnSecondAxis = true;

chart.GapDepth = 80;//Values in percentage
chart.GapWidth = 250;




pres.Write(“D:\Aspose Data\Presentation2.pptx”);

Many Thanks,

Hi,

Please find below my requirements and let me know if these can be acieved using Aspose.Slide.Pptx.ChartEx :

· 18-20 charts on a single slide in readable format<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

· scale break

· Common scale for multiple charts drawn on one slide. There can be max of two scales in a slide. We can evaluate the possibility to define scale by setting common values for Axis attributes –Minimum, maximum and interval to redraw the charts on screen/slide

· Provision to show values as millions/billions/actual

· Provision to manage the decimal places

· To show absolute as well as percentage values in some sections of the graph.

Thanks

Hi,

Please let me know the relevant code for PPT chart .Below is for excel chart:

//Applying a dotted line style on the lines of a SeriesCollection

chart.NSeries[0].Line.Style = Aspose.Cells.Drawing.LineType.Dot;

//Applying a triangular marker style on the data markers of a SeriesCollection

chart.NSeries[0].MarkerStyle = Aspose.Cells.Charts.ChartMarkerType.Triangle;

//Setting the weight of all lines in a SeriesCollection to medium

chart.NSeries[1].Line.Weight = Aspose.Cells.Drawing.WeightType.MediumLine;

Hi,

I am trying to work on chart appearance for pptx chart as described for excel chart here :http://www.aspose.com/docs/display/cellsnet/Setting+Charts+Appearance

Hi,


I have worked over your requirements and have answered almost all the queries related to chart formatting. I have generated an extensive sample code for managing different chart entities. I hope this will be really helpful to you.

public static void MangeChartProperties()
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.LineWithMarkers, 50, 50, 500, 400);


//Setting Major and minor grid lines format for value axis
chart.ValueAxis.MajorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.MajorGridLines.FillFormat.SolidFillColor.Color = Color.Blue;
chart.ValueAxis.MajorGridLines.Width = 5;

chart.ValueAxis.MinorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.MinorGridLines.FillFormat.SolidFillColor.Color = Color.Red;
chart.ValueAxis.MinorGridLines.Width = 3;

chart.ValueAxis.SourceLinked = false;
//chart.ValueAxis.DisplayUnit = DisplayUnitType.Millions;
chart.ValueAxis.DisplayUnit = DisplayUnitType.Thousands;
chart.ValueAxis.NumberFormat = “0.0%”;

//Setting chart maximum, minimum values
chart.ValueAxis.IsAutomaticMajorUnit = false;
chart.ValueAxis.IsAutomaticMaxValue = false;
chart.ValueAxis.IsAutomaticMinorUnit = false;
chart.ValueAxis.IsAutomaticMinValue = false;
chart.ValueAxis.MaxValue = 15f;
chart.ValueAxis.MinValue = -2f;
chart.ValueAxis.MinorUnit = 0.5f;
chart.ValueAxis.MajorUnit = 2.0f;


//Setting Major and minor grid lines format for Category axis
chart.CategoryAxis.MajorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.MajorGridLines.FillFormat.SolidFillColor.Color = Color.Green;
chart.CategoryAxis.MajorGridLines.Width = 5;

chart.CategoryAxis.MinorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.MinorGridLines.FillFormat.SolidFillColor.Color = Color.Yellow;
chart.CategoryAxis.MinorGridLines.Width = 3;



//Setting Category Axis Text Properties
TextFrameEx txt = chart.CategoryAxis.TextProperties;

txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; ;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

//Setting Value Axis Text Properties
TextFrameEx txt2 = chart.ValueAxis.TextProperties;

txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; ;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

//Setting Legends Text Properties

TextFrameEx txt3 = chart.Legend.TextProperties;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; ;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

chart.ValueAxis.AxisLine.Width = 10;
chart.ValueAxis.AxisLine.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.AxisLine.FillFormat.SolidFillColor.Color = Color.Red;



chart.SecondValueAxis.IsVisible = true;
chart.SecondValueAxis.AxisLine.Style = LineStyleEx.ThickBetweenThin;
chart.SecondValueAxis.AxisLine.Width = 20;

// TextFrameEx tf=chart.SecondValueAxis.Title.Text;


//Setting chart back wall color
chart.ChartFormat.Fill.FillType = FillTypeEx.Solid;
chart.ChartFormat.Fill.SolidFillColor.Color = Color.Orange;

//Setting Plot area color
chart.PlotArea.Format.Fill.FillType = FillTypeEx.Solid;
chart.PlotArea.Format.Fill.SolidFillColor.Color = Color.LightCyan;

//working with chart series
ChartSeriesEx series = chart.ChartData.Series[0];

//Setting marker and its properties for chart series
series.MarkerSymbol = MarkerStyleTypeEx.Diamond;
series.MarkerSize = 20;
series.MarkerFill.Fill.FillType = FillTypeEx.Solid;
series.MarkerFill.Fill.SolidFillColor.Color = Color.RosyBrown;
series.MarkerFill.Line.Width= 2;
series.MarkerFill.Line.FillFormat.FillType=FillTypeEx.Solid;
series.MarkerFill.Line.FillFormat.SolidFillColor.Color = Color.Chocolate;

//Setting Line format for chart series
series.Format.Line.DashStyle = LineDashStyleEx.Dot;
series.Format.Line.Style = LineStyleEx.ThickThin;
series.Format.Line.Width = 5d;
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Black;

//Plotting series on secondary axis
series.PlotOnSecondAxis = true;

//Adding Series label and its properties
DataLabelEx label = new DataLabelEx(series);
series.Labels.Add(label);
series.Labels.ShowValue = true;
series.Labels.ShowSeriesName = false;
series.Labels.ShowCategoryName = false;
series.Labels.LinkedSource = false;
series.Labels.NumberFormat = “0.0%”;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.DarkGreen;

//Saving Presentation
pres.Write(“D:\Aspose Data\AxisValue.pptx”);

}

Also, I like to share that Aspose.Slides is fully capable of generating 18-20 charts on single slide as you can do with PowerPoint but generating that much number of charts on single slide may have readability issues. Even you create charts using PowerPoint, you will face the readability issues. Using the above sample code you can set the properties in your accepted values and can observe readability.

In above sample code I have shared with you setting the custom values for maximum, minimum, major unit and minor values for Value axis. I have also shared how to set the values in different DisplyUnits. You can use Thousands, millions or Billions as per your convenience. I have also shared how to set the custom values in percentage format as well. I have also shared how to add and manage chart labels for your convenience.

Lastly, I have not been able to understand your inquiry related to managing decimal values. I am hopeful that above sample code addresses that as well as I have set the values of major and minor units in decimals. Also the chart series values are in decimal values as well. If there is still an inquiry related to managing decimal values, please share that explicitly with us.


The generated chart is added for your convenience.

Many Thanks,

Thank you very much for sharing the code.

I am not gettting the following properties(SourceLinked,NumberFormat and TextProperties):

chart.ValueAxis.SourceLinked = false;

chart.ValueAxis.NumberFormat = "0.0%";

TextFrameEx txt3 = chart.Legend.TextProperties;

Regarding my last query of handling decimal values, I want to display decimal number to certain precision value according to user's choice. If user wants 2 precision value than number 2.345 should be displayed as 2.35.If user wants 1 precision value then the number displayed should be 2.3 and so on.

Hi,


I have attached the image for your kind reference to illustrate you more details about SourceLinked and NumberFormat properties in PowerPoint. I hope the image shared is self explanatory and you can even create a chart in PowerPoint and see the effect by using the mentioned properties. The TextProperties actually returns the text frame for the legends. Actually, all the text in presentation is in TextFrameEx object and it font related properties are managed on paragraphs and portions levels of the text frames. Please visit this documentation link for your kind reference.

Also, your query about setting precision for decimal values is also part of number format. You need to set the number format accordingly to view the desired results. For instance, please replace the following line in my above sample code with the proceeding two lines. You will see the effect by your self.


series.Values[0].Value = 4.35657;
series.Labels.NumberFormat = “#,##0.00”;


Please share, if I may help you further in this regard.

Many Thanks,

Yes i can see the properties but i am not able to set these properties in code behind. Below is the error I am getting:

Aspose.Slides.PPtx.Charts.AxisEx does not contain a defination of 'SourceLinked'

Aspose.Slides.PPtx.Charts.LegendEx does not contain a defination for TextProperties ...........

Also, please let me know if we can have multiple charts with different scale on a single slide.

Hi,


Please try using latest version of Aspose.Slides for .NET 6.8.0 on your end. I have tried the same version and it works for me.

Many Thanks,

Hi,

Please let me know how to create dotted clusteredColumn chart for Slides as shown below:



Column chart after applying line styles

Hi,


Please use the same above sample code and add the following sample code for setting series line format. Please also change the chart type to ClusteredColumn.

//Setting Line format for chart series
series.Format.Line.DashStyle = LineDashStyleEx.Dot;
series.Format.Line.Style = LineStyleEx.Single;
series.Format.Line.Width = 5d;
series.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
series.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;

Many Thanks,

<?xml:namespace prefix = v ns = “urn:schemas-microsoft-com:vml” /><v:shapetype id=_x0000_t75 stroked=“f” filled=“f” path=“m@4@5l@4@11@9@11@9@5xe” o:preferrelative=“t” o:spt=“75” coordsize=“21600,21600”> I have already tried the code suggested by you but its not working. </v:shapetype>

Sorry. its working. i was doing a mistake.

Hi,

As one of my requirements , I also require to have stackedChart as:

30%
35%
70%
60%

Here we need to display % of area covered by series.

Hi,


I have observed your requirements and like to share that you are looking for some thing that is based on calculating each series share for particular category and display that as percentage. I regret to share that even PowerPoint does not provide this feature as well. However, I have created the sample code that will serve your requirement where by I have taken percentage value for every series element in particular category and have calculated its percentage for that category. Then I have added that using custom labels for series. I have created the following code snippet that will serve the purpose.

public static void MangeStackedColumnChartProperties()
{
MemoryStream ms = new MemoryStream();
ms.Position = 0;
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.StackedColumn, 50, 50, 500, 400);


//Setting Major and minor grid lines format for value axis
chart.ValueAxis.MajorGridLines.FillFormat.FillType = FillTypeEx.NoFill;
chart.ValueAxis.MinorGridLines.FillFormat.FillType = FillTypeEx.NoFill;

chart.CategoryAxis.MajorGridLines.FillFormat.FillType = FillTypeEx.NoFill;
chart.CategoryAxis.MinorGridLines.FillFormat.FillType = FillTypeEx.NoFill;

//working with chart series
ChartSeriesEx series = chart.ChartData.Series[0];
ChartDataWorksheet work = chart.ChartData.Series[0].Values[0].ChartDataWorksheet;
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
ChartDataCell cell = fact.GetCell(0, chart.ChartData.Series[0].Values[0].Row, chart.ChartData.Series[0].Values[0].Column);

//Adding Series label and its properties
//For Category 1
double totalSeries = System.Convert.ToDouble(chart.ChartData.Series[0].Values[0].Value) + System.Convert.ToDouble(chart.ChartData.Series[1].Values[0].Value) + System.Convert.ToDouble(chart.ChartData.Series[2].Values[0].Value);
double percent1 = (System.Convert.ToDouble(chart.ChartData.Series[0].Values[0].Value) / totalSeries) * 100;
double percent2 = (System.Convert.ToDouble(chart.ChartData.Series[1].Values[0].Value) / totalSeries) * 100;
double percent3 = (System.Convert.ToDouble(chart.ChartData.Series[2].Values[0].Value) / totalSeries) * 100;
String per1 = string.Format("{0:0.##}", percent1);
String per2 = string.Format("{0:0.##}", percent2);
String per3 = string.Format("{0:0.##}", percent3);

//For Category 2
double totalSeries2 = System.Convert.ToDouble(chart.ChartData.Series[0].Values[1].Value) + System.Convert.ToDouble(chart.ChartData.Series[1].Values[1].Value) + System.Convert.ToDouble(chart.ChartData.Series[1].Values[0].Value);
double percent12 = (System.Convert.ToDouble(chart.ChartData.Series[0].Values[1].Value) / totalSeries2) * 100;
double percent22 = (System.Convert.ToDouble(chart.ChartData.Series[1].Values[1].Value) / totalSeries2) * 100;
double percent32 = (System.Convert.ToDouble(chart.ChartData.Series[2].Values[1].Value) / totalSeries2) * 100;
String per12 = string.Format("{0:0.##}", percent12);
String per22 = string.Format("{0:0.##}", percent22);
String per32 = string.Format("{0:0.##}", percent32);

//For Category 3
double totalSeries3 = System.Convert.ToDouble(chart.ChartData.Series[0].Values[2].Value) + System.Convert.ToDouble(chart.ChartData.Series[1].Values[2].Value) + System.Convert.ToDouble(chart.ChartData.Series[2].Values[2].Value);
double percent13 = (System.Convert.ToDouble(chart.ChartData.Series[0].Values[2].Value) / totalSeries3) * 100;
double percent23 = (System.Convert.ToDouble(chart.ChartData.Series[1].Values[2].Value) / totalSeries3) * 100;
double percent33 = (System.Convert.ToDouble(chart.ChartData.Series[2].Values[2].Value) / totalSeries3) * 100;
String per13 = string.Format("{0:0.##}", percent13);
String per23 = string.Format("{0:0.##}", percent23);
String per33= string.Format("{0:0.##}", percent33);

//For Category 4
double totalSeries4 = System.Convert.ToDouble(chart.ChartData.Series[0].Values[3].Value) + System.Convert.ToDouble(chart.ChartData.Series[1].Values[3].Value) + System.Convert.ToDouble(chart.ChartData.Series[2].Values[3].Value);
double percent14 = (System.Convert.ToDouble(chart.ChartData.Series[0].Values[3].Value) / totalSeries4) * 100;
double percent24 = (System.Convert.ToDouble(chart.ChartData.Series[1].Values[3].Value) / totalSeries4) * 100;
double percent34 = (System.Convert.ToDouble(chart.ChartData.Series[2].Values[3].Value) / totalSeries4) * 100;
String per14 = string.Format("{0:0.##}", percent14);
String per24 = string.Format("{0:0.##}", percent24);
String per34= string.Format("{0:0.##}", percent34);


series.Labels.ShowValue = false;
series.Labels.ShowSeriesName = false;
series.Labels.ShowCategoryName = false;
series.Labels.LinkedSource = false;
series.Labels.ShowPercentage = false;


DataLabelEx label = new DataLabelEx(series);
TextFrameEx txt = label.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per1+ “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType=FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series.Labels.Add(label);


DataLabelEx label12 = new DataLabelEx(series);
txt = label.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per12 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series.Labels.Add(label12);

DataLabelEx label13 = new DataLabelEx(series);
txt = label.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per13 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series.Labels.Add(label13);

DataLabelEx label14 = new DataLabelEx(series);
txt = label.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per14 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series.Labels.Add(label14);
series.Labels.Position = LegendDataLabelPositionEx.BestFit;

/* series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.DarkGreen;
*/



ChartSeriesEx series2 = chart.ChartData.Series[1];
DataLabelEx label2 = new DataLabelEx(series2);
txt = label2.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per2 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series2.Labels.Add(label2);

DataLabelEx label22 = new DataLabelEx(series2);
txt = label22.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per22 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series2.Labels.Add(label22);
DataLabelEx label23 = new DataLabelEx(series2);
txt = label23.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per23 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series2.Labels.Add(label23);

DataLabelEx label24 = new DataLabelEx(series2);
txt = label24.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per24 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series2.Labels.Add(label24);



ChartSeriesEx series3 = chart.ChartData.Series[2];
DataLabelEx label3 = new DataLabelEx(series3);
txt = label3.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per3 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series3.Labels.Add(label3);

DataLabelEx label32 = new DataLabelEx(series3);
txt = label32.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per32 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series3.Labels.Add(label32);

DataLabelEx label33 = new DataLabelEx(series3);
txt = label33.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per33 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series3.Labels.Add(label33);

DataLabelEx label34 = new DataLabelEx(series3);
txt = label34.TextFrame;
txt.Text = “”;
txt.Paragraphs[0].Portions[0].Text = per34 + “%”;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
txt.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
txt.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
series3.Labels.Add(label34);


chart.GapDepth = 0;//Values in percentage
chart.GapWidth = 0;

//Saving Presentation
pres.Write(“D:\Aspose Data\AxisValue.pptx”);

}

However, there has been issue observed in adding custom label. Actually, custom labels are added but only last added custom label is displayed and for first category only. The rest of labels depicts the default chart series values. I have created an issue with ID SLIDESNET-33811 to further investigate and resolve the issue. But the above code will serve the purpose completely for your once the issue will be resolved. I have linked this thread with the issue so that you may be automatically notified once the issue will be fixed.

Many Thanks,

Hi,

AS suggested by you I am not able to do formating of numeric label values

series.Values[0].Value = 4.35657;
series.Labels.NumberFormat = "#,##0.00";

Hi,


Its strange things did not work on your end. Please use the following code snippet to serve the purpose. I have used the same code for my implementation and have shared the generated presentation for your reference. Please observe the values by using edit data option and their respective depiction on chart label.

public static void MangeChartProperties()
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.LineWithMarkers, 50, 50, 500, 400);


//Setting Major and minor grid lines format for value axis
chart.ValueAxis.MajorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.MajorGridLines.FillFormat.SolidFillColor.Color = Color.Blue;
chart.ValueAxis.MajorGridLines.Width = 5;

chart.ValueAxis.MinorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.MinorGridLines.FillFormat.SolidFillColor.Color = Color.Red;
chart.ValueAxis.MinorGridLines.Width = 3;


chart.ValueAxis.SourceLinked = false;
//chart.ValueAxis.DisplayUnit = DisplayUnitType.Millions;
chart.ValueAxis.DisplayUnit = DisplayUnitType.Thousands;
chart.ValueAxis.NumberFormat = “0.0%”;

//Setting chart maximum, minimum values
chart.ValueAxis.IsAutomaticMajorUnit = false;
chart.ValueAxis.IsAutomaticMaxValue = false;
chart.ValueAxis.IsAutomaticMinorUnit = false;
chart.ValueAxis.IsAutomaticMinValue = false;

chart.ValueAxis.MaxValue = 15f;
chart.ValueAxis.MinValue = -2f;
chart.ValueAxis.MinorUnit = 0.5f;
chart.ValueAxis.MajorUnit = 2.0f;


//Setting Major and minor grid lines format for Category axis
chart.CategoryAxis.MajorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.MajorGridLines.FillFormat.SolidFillColor.Color = Color.Green;
chart.CategoryAxis.MajorGridLines.Width = 5;

chart.CategoryAxis.MinorGridLines.FillFormat.FillType = FillTypeEx.Solid;
chart.CategoryAxis.MinorGridLines.FillFormat.SolidFillColor.Color = Color.Yellow;
chart.CategoryAxis.MinorGridLines.Width = 3;



//Setting Category Axis Text Properties
TextFrameEx txt = chart.CategoryAxis.TextProperties;

txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; ;
txt.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

//Setting Value Axis Text Properties
TextFrameEx txt2 = chart.ValueAxis.TextProperties;

txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; ;
txt2.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

//Setting Legends Text Properties

TextFrameEx txt3 = chart.Legend.TextProperties;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; ;
txt3.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;

chart.ValueAxis.AxisLine.Width = 10;
chart.ValueAxis.AxisLine.FillFormat.FillType = FillTypeEx.Solid;
chart.ValueAxis.AxisLine.FillFormat.SolidFillColor.Color = Color.Red;



chart.SecondValueAxis.IsVisible = true;
chart.SecondValueAxis.AxisLine.Style = LineStyleEx.ThickBetweenThin;
chart.SecondValueAxis.AxisLine.Width = 20;

// TextFrameEx tf=chart.SecondValueAxis.Title.Text;


//Setting chart back wall color
chart.ChartFormat.Fill.FillType = FillTypeEx.Solid;
chart.ChartFormat.Fill.SolidFillColor.Color = Color.Orange;

//Setting Plot area color
chart.PlotArea.Format.Fill.FillType = FillTypeEx.Solid;
chart.PlotArea.Format.Fill.SolidFillColor.Color = Color.LightCyan;

//working with chart series
ChartSeriesEx series = chart.ChartData.Series[0];

//Setting marker and its properties for chart series
series.MarkerSymbol = MarkerStyleTypeEx.Diamond;
series.MarkerSize = 20;
series.MarkerFill.Fill.FillType = FillTypeEx.Solid;
series.MarkerFill.Fill.SolidFillColor.Color = Color.RosyBrown;
series.MarkerFill.Line.Width = 2;
series.MarkerFill.Line.FillFormat.FillType = FillTypeEx.Solid;
series.MarkerFill.Line.FillFormat.SolidFillColor.Color = Color.Chocolate;

//Setting Line format for chart series
series.Format.Line.DashStyle = LineDashStyleEx.Dot;
series.Format.Line.Style = LineStyleEx.ThickThin;
series.Format.Line.Width = 5d;
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Black;

//Plotting series on secondary axis
series.PlotOnSecondAxis = true;

//Adding Series label and its properties
DataLabelEx label = new DataLabelEx(series);

series.Labels.Add(label);
series.Labels.ShowValue = true;
series.Labels.ShowSeriesName = false;
series.Labels.ShowCategoryName = false;
series.Labels.LinkedSource = false;
// series.Labels.NumberFormat = “0.0%”;
series.Values[0].Value = 4.35657;
series.Values[1].Value = 2.45325657;
series.Values[2].Value = 6.565657;
series.Values[3].Value = 3.675657;
series.Labels.NumberFormat = “#,##0.00”;

series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 20;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontItalic = NullableBool.True;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.DarkGreen;


//Saving Presentation
pres.Write(“D:\Aspose Data\AxisValue.pptx”);

}


Many Thanks,