Articles in this section
Category / Section

How to render the stacked step line series in WPF Chart?

1 min read

This guide provides step-by-step instructions on rendering stacked step line series using Syncfusion® WPF Chart.

Steps to Render Stacked Step Line Series

Step 1: Create a Custom Class

Create a custom class, StackedStepLineSeries, by inheriting from StepLineSeries.


C#:

public class StackedStepLineSeries : StepLineSeries
{
 
}

Step 2: Override the OnDataSourceChanged Method

Override the OnDataSourceChanged method in the StackedStepLineSeries class to stack data from the provided ItemsSource as shown below:


C#:

public class StackedStepLineSeries : StepLineSeries
{
        public ObservableCollection<Model> Data { get; set; }
 
        public StackedStepLineSeries()
        {
                Data = new ObservableCollection<Model>();
        }
 
        protected override void OnDataSourceChanged(IEnumerable oldValue,   IEnumerable newValue)
        {
                 int index = Area.Series.IndexOf(this);
 
                 if (index > 0 && ItemsSource != Data)
                        UpdateDataSource(index);
                 else
                        base.OnDataSourceChanged(oldValue, newValue);
        }
 
        private void UpdateDataSource(int seriesIndex)
        {
                 Data.Clear();
 
                 var previousSeriesData = Area.Series[seriesIndex - 1].ItemsSource as ObservableCollection<Model>;
                 var currentData = ItemsSource as ObservableCollection<Model>;
 
                for (int i = 0; i < previousSeriesData.Count; i++)
                {
                        Data.Add(new Model() { XData = currentData[i].XData, YData =   previousSeriesData[i].YData + currentData[i].YData });
                }
 
                ItemsSource = Data;
        }
}

Step 3: Create Instances for the Custom Class

Create an instance for custom StackedStepLineSeries class as demonstrated in the following code snippet.


XAML:

<local:StackedStepLineSeries XBindingPath="XData" 
YBindingPath="YData"                              ItemsSource="{Binding Data}"/>   <local:StackedStepLineSeries XBindingPath="XData"
YBindingPath="YData"                             ItemsSource="{Binding Data}"/>   <local:StackedStepLineSeries XBindingPath="XData"
YBindingPath="YData"                             ItemsSource="{Binding Data}"/>

Output:

Chart with stacked stepline series in WPF


Rendering Stacked Step Area Series

You can similarly render StackedStepAreaSeries by inheriting from StepAreaSeries. Additionally, set the Canvas.ZIndex and Interior properties as demonstrated:


XAML:

<local:StackedStepAreaSeries Canvas.ZIndex="3"  
Interior="Red"
XBindingPath="XData" 
YBindingPath="YData"
ItemsSource="{Binding Data}"/>   <local:StackedStepAreaSeries Canvas.ZIndex="2"
Interior="Green"
XBindingPath="XData"
YBindingPath="YData"
ItemsSource="{Binding Data}"/>   <local:StackedStepAreaSeries Canvas.ZIndex="1"
Interior="Blue"
XBindingPath="XData"
YBindingPath="YData"
ItemsSource="{Binding Data}"/>

C#:

public class StackedStepAreaSeries : StepAreaSeries
{
 
}

Output:

Chart with stacked steparea series in WPF


Conclusion

I hope you enjoyed learning how to render the stacked step line series in WPF Chart.

You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied