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

Free Support Forum - aspose.com

Set legend.X combined with LegendPositionType.NotDocked

Hi Laurence,

i have still some trouble with my charts!

//Chart-Legende
chart.Legend.Position = LegendPositionType.NotDocked;
chart.Legend.X = Convert.ToInt32(cells.GetColumnWidth(0) * 30.5);
chart.Legend.Y = 100;
chart.Legend.Width = 400;
chart.Legend.Height = 20;

The width and height of the legend comes up correct but “chart.Legend.X” and “chart.Legend.Y” has no effect, the legend appears on top/left corner.

Am I usering wrong code or is this a bug?

Regards, Stefan

Hi Stefan,

You can try my sample in https://forum.aspose.com/t/118997.

Legend.X and Legend.Y has effect but it’s unit is not same as width/height. Its unit is 1/4000 of the chart area. So please set Legend.X and Legend.Y to 1000 and see what happens.

@WebJumper,
Aspose.Excel is deprecated and no more development is done for it. A new version is introduced Aspose.Cells which contains legacy features as well as the latest ones supported by all versions of MS Excel. It supports creating chart as shown below:

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();

// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];

// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);

// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 5, 0, 15, 5);

// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);

// Saving the Excel file
workbook.Save(dataDir + "output.xls");

A detailed section is here which provides information about handing charts:
Charts

Latest version is available here:
Aspose.Cells for .NET (Latest Version)

A ready to run the solution is present here.