# Bind Chart to Dynamic Series

## Environment

<table>
    <tr>
    <td>Product</td>
    <td>Telerik UI for ASP.NET MVC Chart</td>
    </tr>
    <tr>
    <td>Product Version</td>
    <td>Created with version 2024.4.1112</td>
    </tr>
</table>

## Description

How can I bind the Chart to dynamic series?

## Model

Define the series data and category values in the view model. The `Stack` property in this example stores the stack group, while the Stack100 mode is configured in the Chart.

```C#
using System.Collections.Generic;

public class MySeriesData
{
    public string Name { get; set; }
    public string Stack { get; set; }
    public decimal[] Data { get; set; }
}

public class MyViewModel
{
    public List<string> Categories { get; set; } = new List<string>();
    public List<MySeriesData> Series { get; set; } = new List<MySeriesData>();
}
```

## Example

```Razor HtmlHelper
    @model TelerikAspNetCoreApp4.Models.MyViewModel
 
    @(Html.Kendo().Chart()
          .Name("Chart")
          .Series(series => {
              foreach (var def in Model.Series) {
                  series.Column(def.Data)
                        .Name(def.Name)
                        .Stack(ChartStackType.Stack100, def.Stack);
              }
          })
          .CategoryAxis(axis => axis
             .Categories(Model.Categories.ToArray())
          )
    )
```

```C# Controller
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new MyViewModel();
            model.Categories.AddRange(new string[] { "A", "B", "C" });
    
            model.Series.Add(new MySeriesData()
            {
                Name = "Foo",
                Stack = "A",
                Data = new decimal[] { 1, 2, 3 }
            });
    
            model.Series.Add(new MySeriesData()
            {
                Name = "Bar",
                Stack = "A",
                Data = new decimal[] { 2, 3, 4 }
            });
    
            model.Series.Add(new MySeriesData()
            {
                Name = "Baz",
                Stack = "B",
                Data = new decimal[] { 10, 20, 30 }
            });
    
            return View(model);
        }
    }
```

To see the complete example, refer to the [ASP.NET MVC application](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/ChartDynamicSeries) in the [UI for ASP.NET MVC Examples repository](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master).

## More ASP.NET MVC Chart Resources

* [ASP.NET MVC Chart Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/charts/overview)

* [ASP.NET MVC Chart Demos](https://demos.telerik.com/aspnet-mvc/charts/index)

* [ASP.NET MVC Chart Product Page](https://www.telerik.com/aspnet-mvc/charts)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Chart for ASP.NET MVC](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/chart)

* [Server-Side API Reference of the Chart for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/chart)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
