Charting control

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);

// series.Labels.NumberFormat = “0.0%”;

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,

Hi,

I am not able to set title for Y-Axis doing this:

chart.ValueAxis.Title.Text.Text = "Numbers in billion";

Please let me know the correct code.

Thanks

I was not setting this propert:

chart.ValueAxis.HasTitle = true;

Now its working

Hi,


That is really appreciable you are able to figure out the requirement on your end. Please share, if I may help you further in this regard.

Many Thanks,

Hi ,

Now I have a requirement of displaying data as follows:

40 40
30
25 25
20
2000 2001 2002 2003 2004-jan 2004-feb

Here first 4 column has the data for the whole year. But for the year 2004 we have data for the first two months and rest of the months data is awaited. Please help me accomplishing this requirement.

Thanks

I also want to display value as :

2.00E+07

This is not working

//shows values

series.Labels.ShowValue = true;

series.Labels.NumberFormat = "0.00E+00";

Hi,

Please let me know if there is any update on my last two queries. I am just trying to know the feasibilty to achieve, with the current version of aspose chart.

Thanks.

Hi,


I have worked over your requirements for setting the number format to requested string. It works perfectly on my end. I have modified the code that I have shared with you earlier with following number format and it worked on my end. Please use the following code and I have also shared the generated presentation for your kind reference.

PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
// ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.LineWithMarkers, 50, 50, 500, 400);
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 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 = Aspose.Slides.Pptx.Charts.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.Single;
series.Format.Line.Width = 5d;
series.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
series.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;

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.Labels.NumberFormat = “0.00E+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”);


For your second query mentioned here, unfortunately I have not been able to understand your requisitioner. Kindly, share some more details about the requirement and please also share in the form of sample PowerPoint presentation, so that I may see on my end the way out to achieve that.

Many Thanks,

Hi,

Please show how to set background color of a chart. Below is the code I found which set the background color for the whole slide:

//Set the background color of the Master Slide to Forest Green

//pres.Masters[0].Background.Type = BackgroundTypeEx.OwnBackground;

//pres.Masters[0].Background.FillFormat.FillType = FillTypeEx.Solid;

//pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.LightGray;

I want to do for only chart area.

Here is the code to change background color of chart area:

chart.PlotArea.Format.Fill.FillType = FillTypeEx.Solid;

chart.PlotArea.Format.Fill.SolidFillColor.Color = Color.DarkGray;

I have another query. How can I change the font color of one of the legend. Say for example I have the name for 4 differernt legend and I want to set only one legend to 'Bold'

Hi,


I feel I have shared the code sample for setting the chart background color in previously shared sample codes. Please use the following sample code to serve the purpose and share with us if there is still an issue.

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


Many Thanks,

Hi,


I regret to share that setting the feature for setting the labels properties individually is currently unavailable in Aspose.Slides. I have created an issue with ID SLIDESNET-33828 in our issue tracking system to further investigate the possibility of implementing the mentioned feature. We will share the notification with you as soon as the feature will be available.

I also like to add further that issue SLIDESNET-33811 created in response to your requirements shared over this thread post has also been resolved. Please use the following code sample to serve the purpose.


public static void addLabelsToChart()
{

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;

//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);

ChartSeriesEx series = chart.ChartData.Series[0];
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;
label.Id = 0;
series.Labels.Add(label);


DataLabelEx label12 = new DataLabelEx(series);
txt = label12.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;
label12.Id = 1;
series.Labels.Add(label12);

DataLabelEx label13 = new DataLabelEx(series);
txt = label13.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;
label13.Id = 2;
series.Labels.Add(label13);

DataLabelEx label14 = new DataLabelEx(series);
txt = label14.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;
label14.Id = 3;
series.Labels.Add(label14);


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;
label2.Id = 0;
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;
label22.Id = 1;
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;
label23.Id = 2;
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;
label24.Id = 3;
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;
label3.Id = 0;
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;
label32.Id = 1;
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;
label33.Id = 2;
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;
label34.Id = 3;
series3.Labels.Add(label34);


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

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

Many Thanks,

Im getting the same issue and there is a red line beneath the Color saying that in not in the current context.

Hi Jim,


Can you please share the sample project along with source presentation and generated presentation. Please also share the snapshot of the chart by highlighting the issue incurring.

Many Thanks,

The issues you have found earlier (filed as SLIDESNET-33811) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as SLIDESNET-33828) have been fixed in this update.