ASP.NET Core StockChart Overview

The Telerik UI StockChart TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI StockChart component.

The StockChart is a specialized control visualizing the price movement of any financial instrument over a certain period of time. StockCharts include extensive touch support and a navigator pane for easy browsing of extended time periods. Generally, StockCharts extend the Telerik UI Chart and share most of its features.

Telerik UI for ASP.NET Core Ninja image
New to Telerik UI for ASP.NET Core?

Telerik UI for ASP.NET Core is a professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

To see the component in action, check the examples:

All of the following series types that are supported by the StockChart are also accessible from a Telerik UI Chart:

Basic Configuration

The UI for ASP.NET StockChart makes Ajax requests when it is bound to a data source and has to be configured for Ajax binding.

  1. Add the new action method.

    The following example demonstrates how to add a new action method which returns data to populate the StockChart.

          @(Html.Kendo().StockChart<Kendo.Mvc.Examples.Models.StockDataPoint>()
              .Name("stockChart")
              .Title("The Boeing Company (NYSE:BA)")
              .DataSource(ds => ds.Read(read => read
                  .Action("_BoeingStockData", "Home")
              ))
              .DateField("Date")
          )
    
          <kendo-stockchart name="stockChart"
                  date-field="Date">
              <chart-title text=" The Boeing Company (NYSE:BA)"></chart-title>
              <datasource custom-type="aspnetmvc-ajax"
                      server-paging="true"
                      server-filtering="true"
                      server-grouping="true">
                  <transport>
                      <read  url="@Url.Action("_BoeingStockData", "Financial")"/>
                  </transport>
                   <schema>
                  <model>
                      <fields>
                          <field name="Date" type="date"></field>
                          <field name="Close" type="number"></field>
                          <field name="Volume" type="number"></field>
                          <field name="Open" type="number"></field>
                          <field name="High" type="number"></field>
                          <field name="Low" type="number"></field>
                          <field name="Symbol" type="string"></field>
                      </fields>
                  </model>
              </schema>
              </datasource>
          </kendo-stockchart>
    
          public class StockDataPoint
          {
              public DateTime Date { get; set; }
    
              public decimal Close { get; set; }
    
              public long Volume { get; set; }
    
              public decimal Open { get; set; }
    
              public decimal High { get; set; }
    
              public decimal Low { get; set; }
    
              public string Symbol { get; set; }
          }
    
          public IActionResult Index()
          {
              return View();
          }
    
          public IActionResult _BoeingStockData()
          {
              using (var db = GetContext())
              {
                  // Return the data as JSON.
                  return Json(
                      (from s in db.Stocks
                      where s.Symbol == "BA"
                      select new StockDataPoint
                      {
                          Date = s.Date,
                          Open = s.Open,
                          High = s.High,
                          Low = s.Low,
                          Close = s.Close,
                          Volume = s.Volume
                      }).ToList()
                  );
              }
          }
    
  2. Create the data series.

    The following example demonstrates how to create the main and the navigator data series.

        @(Html.Kendo().StockChart<Kendo.Mvc.Examples.Models.StockDataPoint>()
            .Name("stockChart")
            .Title("The Boeing Company (NYSE:BA)")
            .DataSource(ds => ds.Read(read => read
                .Action("_BoeingStockData", "Home")
            ))
            .DateField("Date")
            .Series(series => {
                series.Candlestick(s => s.Open, s => s.High, s => s.Low, s => s.Close);
            })
            .Navigator(nav => nav
                .Series(series => {
                    series.Line(s => s.Volume);
                })
            )
        )
    
        <kendo-stockchart name="stockChart"
                date-field="Date">
            <chart-title text=" The Boeing Company (NYSE:BA)"></chart-title>
            <datasource custom-type="aspnetmvc-ajax"
                    server-paging="true"
                    server-filtering="true"
                    server-grouping="true">
                <transport>
                    <read  url="@Url.Action("_BoeingStockData", "Financial")"/>
                </transport>
                 <schema>
                <model>
                    <fields>
                        <field name="Date" type="date"></field>
                        <field name="Close" type="number"></field>
                        <field name="Volume" type="number"></field>
                        <field name="Open" type="number"></field>
                        <field name="High" type="number"></field>
                        <field name="Low" type="number"></field>
                        <field name="Symbol" type="string"></field>
                    </fields>
                </model>
            </schema>
            </datasource>
            <series>
                <series-item type="ChartSeriesType.Candlestick" open-field="Open" high-field="High" low-field="Low" close-field="Close"></series-item>
            </series>
            <navigator>
            <navigator-series>
                    <series-item type="ChartSeriesType.Line" field="Volume"></series-item>
                </navigator-series>
                <select from="new DateTime(2009,02,05)" to="new DateTime(2011,10,07)"></select>
            </navigator>
        </kendo-stockchart>
    

Functionality and Features

The StockChart provides options for binding it to data.

Events

You can subscribe to all StockChart events.

Handling Events by Handler Name

The following example demonstrates how to subscribe to events by a handler name.

    @(Html.Kendo().StockChart<Kendo.Mvc.Examples.Models.StockDataPoint>()
        .Name("stockChart")
        .Title("The Boeing Company (NYSE:BA)")
        .DateField("Date")
        .Series(series => {
            series.Candlestick(s => s.Open, s => s.High, s => s.Low, s => s.Close);
        })

        .Events((Action<Kendo.Mvc.UI.Fluent.StockChartEventBuilder>)(x => 
            x.DataBound("stockChart_dataBound")
            .SeriesClick("stockChart_seriesClick")
            )
        )

    )

    <script>
        function stockChart_dataBound(e) {
            // Handle the dataBound event.
        }

        function stockChart_seriesClick(e) {
            // Handle the seriesClick event.
        }
    </script>
    <kendo-stockchart name="stockChart"
            date-field="Date" 
            on-data-bound="stockChart_dataBound"
            on-series-click="stockChart_seriesClick">
        <chart-title text=" The Boeing Company (NYSE:BA)"></chart-title>
        <series>
            <series-item type="ChartSeriesType.Candlestick" open-field="Open" high-field="High" low-field="Low" close-field="Close"></series-item>
        </series>
    </kendo-stockchart>
    <script>
        function stockChart_dataBound(e) {
            // Handle the dataBound event.
        }

         function stockChart_seriesClick(e) {
             // Handle the seriesClick event.
         }
     </script>   

Handling Events by Template Delegate

The following example demonstrates how to subscribe to events by a template delegate.

    @(Html.Kendo().StockChart<Kendo.Mvc.Examples.Models.StockDataPoint>()
        .Name("stockChart")
        .Title("The Boeing Company (NYSE:BA)")
        .DateField("Date")
        .Series(series => {
            series.Candlestick(s => s.Open, s => s.High, s => s.Low, s => s.Close);
        })
        .Events((Action<Kendo.Mvc.UI.Fluent.StockChartEventBuilder>)(e => e
          .DataBound(@<text>
               function(e) {
                   //Handle the dataBound event inline.
               }
          </text>)
          .SeriesClick(@<text>
               function(e) {
                   //Handle the seriesClick event inline.
               }
          </text>)
         )
        )
    )

Referencing Existing Instances

To reference an existing Kendo UI StockChart instance, use the jQuery.data() configuration option. Once a reference is established, use the StockChart client-side API to control its behavior.

// Place the following after the declaration of the Barcode for ASP.NET Core.
<script>
    $(function() {
        // The Name() of the StockChart is used to get its client-side instance.
        var chart = $("#stockChart").data("kendoStockChart");
    });
</script>

See Also

In this article