Free Support Forum - aspose.com

Unable to position legend on top of chart area

I am trying to overlay the legend on a 355 x 250 chart using the following code:

oChart.Legend.Overlay=NullableBool.True
oChart.Legend.X = 100
oChart.Legend.Y = 175

However, regardless of the values I set for X and Y, the legend keeps being pushed to the outside of the chart area (see attachment).Any help is appreciated. I'm using Slides 7.4.0.0.

Thanks,

Scott

Hi Scott,

I have observed the requirements specified by you. Actually,
when you set the position of legends in the chart area you need to give X, Y
values from 0 to 1. 0 referring as top left corner of chart area and 1
referring as bottom right corner of the chart area. Whatever position you need
to give within the chart area, you need to map in between 0 and 1 and in
accordance with chart width and height. The following sample code will help you
understand the concept. Please share, if I may help you further in this regard.

PresentationEx pres = new PresentationEx();

SlideEx slide = pres.Slides[0];

int ChartWidth = 400;

int ChartHeight = 400;

ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 100, 100, ChartWidth, ChartHeight);

float LegendXPosition = 100;

float LegendYPosition = 175;

//The plotting position in chart area is from 0 to 1 w.r.t maximum chart width and height

//So we need to map the desired legend poistion based on this mapping

float newLegendXPosition = (float)(LegendXPosition / ChartWidth);

float newLegendYPosition = (float)(LegendYPosition / ChartHeight);

chart.Legend.X = newLegendXPosition;

chart.Legend.Y = newLegendYPosition;

pres.Save("D:\\Aspose Data\\TestLegend.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

<span style=“font-size:11.0pt;line-height:107%;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-bidi-font-family:“Times New Roman”;
mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA”>Many Thanks,<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

<![endif]–>