Please see this link
Need to generate same functioanlity with barStack Chart, Showing total on the top of chart
Please provide code/reference.
Please see this link
Need to generate same functioanlity with barStack Chart, Showing total on the top of chart
Please provide code/reference.
Hi,
Please see the sample code for your reference for your needs. Also, you cannot just place the total labels on top of the bars as it is the limitation in MS Excel.
e.g
Sample code:
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Put chart data
sheet.Cells[0, 0].PutValue("S1");
sheet.Cells[0, 1].PutValue(2);
sheet.Cells[0, 2].PutValue(4);
sheet.Cells[0, 3].PutValue(6);
sheet.Cells[1, 0].PutValue("S2");
sheet.Cells[1, 1].PutValue(1);
sheet.Cells[1, 2].PutValue(5);
sheet.Cells[1, 3].PutValue(3);
sheet.Cells[2, 0].PutValue("S3");
sheet.Cells[2, 1].PutValue(1);
sheet.Cells[2, 2].PutValue(2);
sheet.Cells[2, 3].PutValue(3);
//Set total fromula
sheet.Cells[3, 1].Formula = "sum(B1:B3)";
sheet.Cells[3, 2].Formula = "sum(C1:C3)";
sheet.Cells[3, 3].Formula = "sum(D1:D3)";
workbook.CalculateFormula();
//Generate the first chart
int chartIndex = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 5, 5, 22, 12);
Chart chart = sheet.Charts[chartIndex];
//Insert series
chart.NSeries.Add("B1:D3", false);
chart.Title.Text = "test";
//Add datalabel for last series
Series serieLast = chart.NSeries[2];
int pointCount = serieLast.Points.Count;
for (int i = 0; i < pointCount; i++)
{
DataLabels dl = serieLast.Points[i].DataLabels;
dl.Text = sheet.Cells[3, i + 1].Value.ToString();
}
chart.ToImage(@"e:\test2\out1.png");
workbook.Save(@"e:\test2\out2.xlsx");
Please refer to the above code and write your own code to accomplish the tasks for your scenario.
Hope, this helps a bit.
Thank you.