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

Free Support Forum - aspose.com

How to set the chart legend or title X and Y position with aspose.14.8

hi team,
I am facing issues with my PPT that the chart title is overlapping the legend.

Could you please let me know if I can set the legend and title X and y so that it doesnot overlap.

Please find the below code tat i am using to create the pie chart and attached pie chart exported with this code.

var rect = slide.Shapes.AddAutoShape(ShapeType.Rectangle, Xval, Yval, 330, pieCount>2?150:180);
rect.FillFormat.FillType = FillType.Solid;
rect.FillFormat.SolidFillColor.Color = Color.White;
var chart = slide.Shapes.AddChart(ChartType.Pie, Xval, Yval, 320, pieCount>2?140:175);
chart.Name = Configuration.DASHBOARD_COMPCHART + (shapeID++).ToString();
AddShape(chart, true);

                    chart.PlotArea.Height = pieCount>2?0.5f:0.8f; // chart.Heigh * 0.5 = 400 * 0.5 = 200
                    chart.PlotArea.Width = pieCount>2?0.5f:0.8f; // Chart.Width * 0.5 = 500 * 0.5 = 250
                    chart.PlotArea.X = 0f; // chart.X = 500 * 0.25 = 125
                    chart.PlotArea.Y = 50f; // chart.Y = 400 * 0.25 = 100

                    ITextFrame text = chart.ChartTitle.AddTextFrameForOverriding("");
                    text.Text = summary.ScoresTypeName;
                    text.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 12;
                    text.Paragraphs[0].Portions[0].PortionFormat.FontBold = NullableBool.True;
                    text.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
                    text.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
                    Paragraph titlePar = new Paragraph();
                    titlePar.Text = "Items Included in Comparison: " + summary.ItemsCount.ToString();
                    titlePar.Portions[0].PortionFormat.FontHeight = 10;
                    titlePar.Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
                    titlePar.Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
                    text.Paragraphs.Add(titlePar);
                    chart.ChartData.Series.Clear();
                    chart.ChartData.Categories.Clear();
                    chart.ChartData.Categories.Add(summary.AboveName + ", " + processPercentForRTL(Math.Round(summary.ItemsAbove).ToString(), LanguageIsRightToLeft));
                    chart.ChartData.Categories.Add(summary.OnParName + ", " + processPercentForRTL(Math.Round(summary.ItemsOnPar).ToString(), LanguageIsRightToLeft));
                    chart.ChartData.Categories.Add(summary.BellowName + ", " + processPercentForRTL(Math.Round(summary.ItemsBellow).ToString(), LanguageIsRightToLeft));
                    chart.ChartData.Series.Add(summary.ScoresTypeName, ChartType.Pie);
                    IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook;
                    IChartDataPoint datapoint = chart.ChartData.Series[0].DataPoints.AddDataPointForPieSeries(workbook.GetCell(0, 1, 1, summary.ItemsAbove));
                    datapoint.Format.Fill.FillType = FillType.Solid;
                    datapoint.Format.Fill.SolidFillColor.Color = DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-PieChart-ItemsAbove-Color").GetColor();
                    datapoint = chart.ChartData.Series[0].DataPoints.AddDataPointForPieSeries(workbook.GetCell(0, 2, 1, summary.ItemsOnPar));
                    datapoint.Format.Fill.FillType = FillType.Solid;
                    datapoint.Format.Fill.SolidFillColor.Color = DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-PieChart-ItemsOnPar-Color").GetColor();
                    datapoint = chart.ChartData.Series[0].DataPoints.AddDataPointForPieSeries(workbook.GetCell(0, 3, 1, summary.ItemsBellow));
                    datapoint.Format.Fill.FillType = FillType.Solid;
                    datapoint.Format.Fill.SolidFillColor.Color = DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-PieChart-ItemsBellow-Color").GetColor();
                    chart.ChartData.Series[0].Explosion = 2;
                    chart.Legend.TextFormat.PortionFormat.FontHeight =pieCount>2?9: 10;
                    chart.Legend.Format.Line.FillFormat.FillType = FillType.Solid;
                    chart.Legend.Format.Line.FillFormat.SolidFillColor.Color = Color.Black;
                    chart.Legend.TextFormat.ParagraphFormat.EastAsianLineBreak = NullableBool.False;

QVExport (16).zip (38.6 KB)

@Priyarav87,

I have observed your comments. Can you please try to use Aspose.Slides latest version 17.8 on your end. If there is still an issue than please share complete sample project, environment details so that we may further investigate to help you out.

Hi,
I am sorry the project has lot of dependency on this version of Aspose. I cannot update the refrence and test now as I dont have much time to test it out fully for all languages that our application support. All I want to know whether it is an issue with this version of aspose and a limitation. If so we can tell our client to give us sometime. Please ASAP. Really in need of your suggestion and help here.

Issue happens only for the Espanol(mexico) and American Latina languages and that too only in PPT. Is there an option to set the X and y attributes of either the chart title or legend? If so can you please point me how to set it properly. Right now only option that I can think of is to reduce the font size so that it does not overlap but that comes at the cost of quality making the PPTX unreadable.

@Priyarav87,

I have observed your requirements for setting custom position values for chart legends and title. All you need to do is set to set the position values as a fraction of the width/height of the chart. Please check following sample code for your convenience and same approach can be used for title as well.

using (Presentation pres = new Presentation())
{
   IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 500,500);
   chart.Legend.X = 50 / chart.Width;
   chart.Legend.Y = 50 / chart.Height;
   chart.Legend.Width = 100 / chart.Width;
   chart.Legend.Height = 100 / chart.Height;
   pres.Save(outPath, SaveFormat.Pptx);
}