Hi,
Well, you may use escape sequence character i.e.., '\n' while putting the long text into the source cells to insert line break for legend entries for your need.
See the following updated code:
private Aspose.Cells.Chart createWorkbookChart()
{
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Data";
Aspose.Cells.Cells cells = workbook.Worksheets[0].Cells;
workbook.ChangePalette(Color.Orange, 53);
workbook.ChangePalette(Color.LightBlue, 54);
workbook.ChangePalette(Color.LightCoral, 55);
workbook.ChangePalette(Color.Indigo, 52);
Color[] colors = workbook.Colors;
cells["A1"].PutValue("Excelsior lasalle property fund LLC ");
cells["A2"].PutValue("Excelsior lasalle property fund\n LLC property fund LLC ");
cells["A3"].PutValue("Germany");
cells["A4"].PutValue("England");
cells["A5"].PutValue("Sweden");
cells["B1"].PutValue("Sale");
cells["B2"].PutValue(0.32);
cells["B3"].PutValue(0.62);
cells["B4"].PutValue(0.06);
cells["B5"].PutValue(0.06);
int sheetIndex = workbook.Worksheets.Add(Aspose.Cells.SheetType.Chart);
sheet = workbook.Worksheets[sheetIndex];
sheet.Name = "Chart";
int chartIndex = 0;
chartIndex = sheet.Charts.Add(Aspose.Cells.ChartType.Pie, 1, 3, 25, 12);
Aspose.Cells.Chart c = sheet.Charts[chartIndex];
c.ChartObject.Height = 250;
c.ChartObject.Width = 350;
c.PlotArea.Width = 2700;
c.PlotArea.Height = 2700;
c.PlotArea.X = 0;
c.PlotArea.Y = 800;
c.Legend.Border.IsVisible = false;
c.Legend.AutoScaleFont = true;
c.Legend.AutoScaleFont = false;
c.Legend.TextFont.Name = "Arial";
c.Legend.TextFont.Size = 7;
c.ChartObject.Height = 275;
c.ChartObject.Width = 450;
//checking to see the length of legend
c.Legend.TextFont.Name = "Arial";
c.Legend.TextFont.Size = 7;
c.Legend.Position = Aspose.Cells.LegendPositionType.Right;
c.ChartArea.Background = Aspose.Cells.BackgroundMode.Transparent;
c.NSeries.Add("Data!B2:B5", true);
c.NSeries.CategoryData = "Data!A2:A5";
Aspose.Cells.DataLabels datalabels;
for (int i = 0; i < c.NSeries.Count; i++)
{
datalabels = c.NSeries[i].DataLabels;
//datalabels.IsValueShown = true;
datalabels.IsPercentageShown = true;
datalabels.NumberFormat = "0%";
datalabels.Postion = Aspose.Cells.LabelPositionType.OutsideEnd;
datalabels.TextFont.Name = "Arial";
datalabels.TextFont.Size = 7;
}
return c;
}
Thank you.
Amjad Sahi
Support Developer,
Aspose Sialkot Team
Contact Us