Hi,
I am trying to set the Legend Custom Position but its not applying on chart.
How can i do that? I am using below code sniff.
chart.Legend.Position = LegendPositionTypeEx.NotDefined;
chart.Legend.X = chart.X + (chart.PlotArea.Width)* chart.Width;
chart.Legend.Y = chart.Y;
chart.Width = chart.Width - (chart.PlotArea.Width * chart.Width);
chart.Height = chart.Height;
But its not working for me. It always take the position as "Right" and does not set custom Height and Width.
Thanks,
Amit
Hi Amit,
I have observed the requirement shared and like to share that the feature for setting the legend position is working. You need to set the position values from 0 to 1. 0 means the top left corner of the chart and 1 means the bottom right corner of the chart. Please use the following sample code for your convenience.
public static void AddMultipleChart()
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 50, 50, 500, 450);
//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
chart.SecondValueAxis.IsVisible = true;
chart.SecondCategoryAxis.IsVisible = true;
//Adding new series
int id = chart.ChartData.Series.Add(fact.GetCell(0, 0, 4, “Line 1”), ChartTypeEx.Line);
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[id];
//Add Series values
series.Values.Add(fact.GetCell(0, 1, 4, 1));
series.Values.Add(fact.GetCell(0, 2, 4, 4));
series.Values.Add(fact.GetCell(0, 3, 4, 2));
series.Values.Add(fact.GetCell(0, 4, 4, 6));
//Changing the chart series marker
series.MarkerSize = 10;
series.MarkerSymbol = MarkerStyleTypeEx.Star;
series.PlotOnSecondAxis = true;
// chart.Legend.Position = LegendPositionTypeEx.Left;
chart.Legend.Position = LegendPositionTypeEx.NotDefined;
chart.Legend.X = 0;
chart.Legend.Y = 0;
chart.Legend.X = 1;
chart.Legend.Y = 1;
pres.Write(“D:\Aspose Data\TestChart.pptx”);
}
Please share, if I may help you further in this regard.
Many Thanks,