Skip to content

StackedAreaSeries will not display correctly with Negative value #2073

@gang929

Description

@gang929

For the following data, StackedAreaSeries will not display correctly.
The Negative+Positive values are not calculated correctly for the stacked graphics
aaaa -52.89 -50.35 -42.11 100 -34.56 -28.33
bbbb 1404.4 1404.4 1327.89 1383.78 1365.07 1235.7

In Excel, it show as bellow

Image

Fix it as bellow

diff --git a/src/LiveChartsCore/Kernel/Stacker.cs b/src/LiveChartsCore/Kernel/Stacker.cs
index 473f2b7c6..1e0341cbb 100644
--- a/src/LiveChartsCore/Kernel/Stacker.cs
+++ b/src/LiveChartsCore/Kernel/Stacker.cs
@@ -125,16 +125,22 @@ public class Stacker
         if (value >= 0)
         {
             currentStack.End += value;
+            currentStack.NegativeEnd += value;
             var positiveTotal = _totals[index].Positive + value;
             _totals[index].Positive = positiveTotal;
+            var negativeTotal = _totals[index].Negative + value;
+            _totals[index].Negative = negativeTotal;

             return positiveTotal;
         }
         else
         {
+            currentStack.End += value;
             currentStack.NegativeEnd += value;
             var negativeTotal = _totals[index].Negative + value;
             _totals[index].Negative = negativeTotal;
+            var positiveTotal = _totals[index].Positive + value;
+            _totals[index].Positive = positiveTotal;

             return negativeTotal;
         }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions