# Adding Data to Series

## Content



When it comes to adding data to series, FlexChart provides a powerful way through binding. You can bind series in FlexChart with multiple data sources, which enables you to combine data from multiple data sources. To plot data from multiple data sources, you need to use the Series.<span data-popup-content="This property is available in \u003ca href=\u0022/componentone/api/wpf/online-flexchart/dotnet-api/C1.WPF.Chart/C1.WPF.Chart.Series.ItemsSource.html\u0022\u003e.NET\u003c/a\u003e and \u003ca href=\u0022/componentone/api/wpf/online-flexchart/dotnet-api/C1.WPF.Chart/C1.WPF.Chart.Series.ItemsSource.html\u0022\u003e.NET Framework\u003c/a\u003e." data-popup-title="ItemsSource" data-popup-theme="ui-tooltip-green qtip-green">ItemsSource</span> property.

See the following code for reference. Notice that the following code user the **DataCreator.cs** class to generate data.

**xml**

```xml
<c1:C1FlexChart x:Name="flexChart" 
                ItemsSource="{Binding DataContext.Data}" 
                ChartType="Scatter">
    <c1:C1FlexChart.Series>
        <c1:Series  x:Name="Function1" 
                    SeriesName="Function1" 
                    BindingX ="XVals" 
                    Binding="YVals"/>
        <c1:Series  x:Name="Function2" 
                    SeriesName="Function2" 
                    BindingX ="XVals" 
                    Binding="YVals"/>
    </c1:C1FlexChart.Series>
</c1:C1FlexChart>
```

### Code

```csharp
class DataCreator
{
    public delegate double MathActionDouble(double num);
    public delegate double MathActionInt(int num);
    public static List<DataPoint> Create(MathActionDouble function, double from, double to, double step)
    {
        var result = new List<DataPoint>();
        var count = (to - from) / step;
        for (double r = from; r < to; r += step)
        {
            result.Add(new DataPoint()
            {
                XVals = r,
                YVals = function(r)
            });
        }
        return result;
    }
    public static List<DataPoint> Create(MathActionInt function, int from, int to, int step)
    {
        var result = new List<DataPoint>();
        var count = (to - from) / step;
        for (int r = from; r < to; r += step)
        {
            result.Add(new DataPoint()
            {
                XVals = r,
                YVals = function(r)
            });
        }
        return result;
    }
    public static List<DataPoint> Create(MathActionDouble functionX, MathActionDouble functionY, int ptsCount)
    {
        var result = new List<DataPoint>();
        for (double i = 0; i < ptsCount; i++)
        {
            result.Add(new DataPoint()
            {
                XVals = functionX(i),
                YVals = functionY(i)
            });
        }
        return result;
    }
}
public class DataPoint
{
    public double XVals { get; set; }
    public double YVals { get; set; }
}
```

```csharp
public partial class MainWindow : Window
{
    List<DataPoint> _function1Source;
    List<DataPoint> _function2Source;
    public MainWindow()
    {
        this.InitializeComponent();
        this.Loaded += Form_Loaded;
    }
    private void Form_Loaded(object sender, EventArgs e)
    {
        SetupChart();
    }
    void SetupChart()
    {
        flexChart.BeginUpdate();
        this.Function1.ItemsSource = Function1Source;
        this.Function2.ItemsSource = Function2Source;
        flexChart.EndUpdate();
    }
    public List<DataPoint> Function1Source
    {
        get
        {
            if (_function1Source == null)
            {
                _function1Source = DataCreator.Create(x => 2 * Math.Sin(0.16 * x), y => 2 * Math.Cos(0.12 * y), 160);
            }
            return _function1Source;
        }
    }
    public List<DataPoint> Function2Source
    {
        get
        {
            if (_function2Source == null)
            {
                _function2Source = DataCreator.Create(x => Math.Sin(0.1 * x), y => Math.Cos(0.15 * y), 160);
            }
            return _function2Source;
        }
    }
}
```

![](https://cdn.mescius.io/document-site-files/images/8ba28e07-1633-4a6a-9114-13b9f1f04eed/images/imagesext/seriesbinding.png)