# Bind Chart to SignalR

## 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 a [SignalR](https://dotnet.microsoft.com/en-us/apps/aspnet/signalr) DataSource?

## Solution

```Razor HtmlHelper
    <script src="https://cdn.jsdelivr.net/npm/signalr@2.4.3/jquery.signalR.min.js"></script>

    @(Html.Kendo().Notification()
      .Name("notification")
      .Width("100%")
      .Position(position => position.Top(0).Left(0))
    )
    @(Html.Kendo().Chart<TelerikAspNetCoreApp3.Models.ProductViewModel>()
            .Name("chart")
            .Legend(false)
            .DataSource(dataSource => dataSource
                .SignalR()
                .AutoSync(true)
                .Events(events => events.Push(@<text>
                                                   function(e) {
                                                        var notification = $("#notification").data("kendoNotification");
                                                        notification.success(e.type);
                                                   }
                                               </text>))
                .Sort(s => s.Add("CreatedAt").Descending())
                .Transport(tr => tr
                    .Promise("hubStart")
                    .Hub("hub")
                    .Client(c => c
                        .Read("read")
                        .Create("create")
                        .Update("update")
                        .Destroy("destroy"))
                    .Server(s => s
                        .Read("read")
                        .Create("create")
                        .Update("update")
                    .Destroy("destroy"))
                )
                .Schema(schema => schema
                    .Model(model =>
                    {
                        model.Id("ID");
                        model.Field("ID", typeof(string)).Editable(false);
                        model.Field("CreatedAt", typeof(DateTime));
                        model.Field("UnitPrice", typeof(int));
                    }
                ))
            )
            .Series(series =>
            {
                series.Line(
                    model => model.UnitPrice,
                    categoryExpression: model => model.ProductName
                );
            })
            .Transitions(false)
            .CategoryAxis(axis =>
                axis.Labels(labels => labels.Rotation(-90))
            )
    )
```

```JavaScript
    <script>
        var hubUrl = "path/to/hub";
        var connection = $.hubConnection(hubUrl, { useDefaultPath: false });
        var hub = connection.createHubProxy("productHub");
        var hubStart = connection.start({ jsonp: true });
    </script>
```

```CSS Styles
  <style>
    .footer:first-of-type {
        display: none !important;
    }
  </style>
```

For the complete implementation, 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/ChartSignalR) 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)
