Need Solution for Stacked Column Regarding Data Mapping Allignment

Need solution for Stacked column regarding data mapping allignment, example data we have used
exampledata.png (7.5 KB)
output
image.png (7.9 KB)

Similar to this we have generated similar stacked column with different values are working and alligning correctly
image.png (11.4 KB)

@Sanjai2001

Can you please provide more details about the specific issue you are facing with the stacked column alignment? What values are you using, and how do they differ from the working examples?

Working data
image.png (8.5 KB)

Not working data
exampledata.png (7.5 KB)

@Sanjai2001,
I need some time to check the problem. I will get back to you soon.

@Sanjai2001,
Could you please share a code example you used and describe what is wrong?

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.

@Sanjai2001,
Thank you for the details. I need some time to check the problem. I will get back to you soon.

@Sanjai2001,
Thank you for your patience. I’ve reproduced the problem with the segment proportions of StackedColumn charts generated with Aspose.Slides for .NET.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-44821

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

I am currently working with the Aspose.Slides.NET library, version 23.12.0 , to implement a StackedColumn Chart in my project, which is built on .NET Framework 5.0 . I want to clarify that this is unrelated to Aspose.OCR.

@Sanjai2001,
Thank you for the message. Our developers are actively working on the issue. We will keep you updated.

Any Updates?

@Sanjai2001,
Our developers are still working on the issue. Unfortunately, I don’t have any additional information yet.

@Sanjai2001,
This behavior is normal and expected—it mirrors PowerPoint. By default, the vertical axis automatically calculates its minimum and maximum values based on the series data. You can verify this by opening the presentation in PowerPoint and enabling the vertical axis display.

To achieve the desired behavior, simply disable the automatic minimum calculation.

This can be done like this:

chart.Axes.VerticalAxis.IsAutomaticMinValue = false;

Full CreateAMCStackedColumn method code:

public static IChart CreateAMCStackedColumn(IChart chart, System.Data.DataTable dtrow, ISlide slide)
{
    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.VerticalAxis.IsAutomaticMinValue = false;
    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;

    return chart;
}

More examples: Chart Axis|Aspose.Slides Documentation