Code example:
public static IChart CreateAMCStackedColumn(IChart chart, System.Data.DataTable dtrow, ISlide slide)
{
try
{
chart.TextFormat.PortionFormat.FontHeight = 11;
Color[] colorlist = new Color[] { Color.FromArgb(40, 60, 131), Color.FromArgb(139, 151, 188), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102), Color.FromArgb(40, 60, 131), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(139, 151, 188), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102), Color.FromArgb(40, 60, 131), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(139, 151, 188), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102), Color.FromArgb(40, 60, 131), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(139, 151, 188), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102), Color.FromArgb(40, 60, 131), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(139, 151, 188), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102), Color.FromArgb(40, 60, 131), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(139, 151, 188), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102), Color.FromArgb(40, 60, 131), Color.FromArgb(75, 108, 161), Color.FromArgb(111, 137, 190), Color.FromArgb(139, 151, 188), Color.FromArgb(138, 213, 240), Color.FromArgb(77, 95, 135), Color.FromArgb(199, 201, 221), Color.FromArgb(23, 59, 102) };
Color[] colorlist1 = new Color[] { Color.FromArgb(23, 59, 102), Color.FromArgb(199, 201, 221), Color.FromArgb(77, 95, 135), Color.FromArgb(138, 213, 240), Color.FromArgb(139, 151, 188), Color.FromArgb(111, 137, 190), Color.FromArgb(75, 108, 161), Color.FromArgb(40, 60, 131) };
chart.TextFormat.PortionFormat.FontHeight = 10;
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
IAxesManager yAxis = chart.Axes;
chart.Axes.VerticalAxis.IsVisible = false;
// chart.Legend.Position = Aspose.Slides.Charts.LegendPositionType.Bottom;
chart.Legend.TextFormat.PortionFormat.FontHeight = 10;
int defaultWorksheetIndex = 0;
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.Width = 0;
chart.Axes.VerticalAxis.MinorGridLinesFormat.Line.Width = 0;
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.Solid;
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.Width = 0;
chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.SolidFillColor.Color = Color.Gray;
//chart.Width = 600;
chart.Legend.TextFormat.PortionFormat.FontHeight = 10;
chart.Legend.TextFormat.PortionFormat.LatinFont = new FontData("Arial");
chart.Axes.HorizontalAxis.TextFormat.PortionFormat.LatinFont = new FontData("Arial");
chart.Axes.VerticalAxis.TextFormat.PortionFormat.LatinFont = new FontData("Arial");
chart.HasLegend = true;
// chart.Legend.Position = Aspose.Slides.Charts.LegendPositionType.Bottom;
chart.Legend.Position = Aspose.Slides.Charts.LegendPositionType.Bottom;
for (int count = 1; count < dtrow.Columns.Count; count++)
{
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, count + 1, dtrow.Columns[count].ColumnName.ToString()), chart.Type);
}
for (int count = 0; count < dtrow.Rows.Count; count++)
{
DataRow row = dtrow.Rows[count];
chart.ChartData.Categories.Add(fact.GetCell(0, count + 1, 0, row[0].ToString().ToString()));
}
IChartSeries series = chart.ChartData.Series[0];
series.DataPoints.Clear();
for (int colcnt = 0; colcnt < dtrow.Columns.Count - 1; colcnt++)
{
series = chart.ChartData.Series[colcnt];
for (int Rowcount = 0; Rowcount < dtrow.Rows.Count; Rowcount++)
{
DataRow row = dtrow.Rows[Rowcount];
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, colcnt + 1, Rowcount + 1, row[colcnt + 1]));
series.Format.Fill.FillType = FillType.Solid;
series.Labels.DefaultDataLabelFormat.ShowValue = true;
series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FontHeight = 10;
series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid;
series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
series.Format.Fill.SolidFillColor.Color = colorlist[colcnt];
for (int pnt = 0; pnt < series.DataPoints.Count; pnt++)
{
IDataLabel lbl = series.DataPoints[pnt].Label;
Aspose.Slides.Charts.IChartDataPoint point = series.DataPoints[pnt];
IPortion port = new Portion();
IDoubleChartValue ch = series.DataPoints[pnt].Value;
double intValue = ch.ToDouble();
port.Text = intValue > 0.00 || intValue < 0.00 ? String.Format("{0:0} %", series.DataPoints[pnt].Value.Data) : string.Empty;
//port.Text = intValue > 0.00 || intValue < 0.00 ? String.Format("{0:00} %", series.DataPoints[pnt].Value.Data) : string.Empty;
port.PortionFormat.FontHeight = 9f;
port.PortionFormat.FillFormat.FillType = FillType.Solid;
port.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
lbl.TextFrameForOverriding.Text = "";
IParagraph para = lbl.TextFrameForOverriding.Paragraphs[0];
para.Portions.Add(port);
}
}
}
if (series.Overlap == 0)
{
series.ParentSeriesGroup.Overlap = 100;
}
series.ParentSeriesGroup.GapWidth = 80;
series.ShowMeanLine = false;
}
catch (Exception ex)
{
}
return chart;
}
Issue Description
In a stacked column chart, each series’ data point represents a percentage of the total value (100%). The expected behavior is that larger data points take up more visual space, while smaller data points take up proportionally less space.
Working Data:
When using values like ‘77.7’ and ‘22.3’, the chart correctly allocates space, making the ‘77.7’ segment occupy more visual space in the stack compared to the ‘22.3’ segment.
This is expected behavior since:
77.7% of the total should visually appear larger than 22.3%.
Not Working Data:
When using values like ‘92.7’ and ‘7.3’, the chart fails to adapt, showing these segments in incorrect proportions. The ‘7.3’ segment should occupy a very small part of the total stack, but instead, it might appear disproportionately large or too small.