Edit this page

StockChart HtmlHelper Overview

The StockChart HtmlHelper extension is a server-side wrapper for the Kendo UI StockChart widget.

Getting Started

The Basics

There are two ways to bind a Kendo UI StockChart for ASP.NET MVC:

  • server—The StockChart is bound to a supplied model.
  • ajax—The StockChart makes Ajax requests when binding.

Server Binding

Below are listed the steps for you to follow when configuring the Kendo UI StockChart for server binding.

  1. Make sure you followed all the steps from the introductory article on Telerik UI for ASP.NET MVC.

  2. Create a new action method and pass the data list as the model.

    Example
        public ActionResult Index()
        {
            return View(ChartDataRepository.BoeingStockData());
        }
    
  3. Make your view strongly typed.

    Example
    
            <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
                     Inherits="System.Web.Mvc.ViewPage<IEnumerable<Kendo.Mvc.Examples.Models.StockDataPoint>>" %>
    
    
            @model IEnumerable<Kendo.Mvc.Examples.Models.StockDataPoint>
    
  4. Add a server-bound StockChart.

    Example
    
            <%: Html.Kendo().StockChart(Model)
            .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);
            })
            .Navigator(nav => nav
                .Series(series => {
                    series.Line(s => s.Volume);
                })
            )
            %>
    
    
            @(Html.Kendo().StockChart(Model)
            .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);
            })
            .Navigator(nav => nav
                .Series(series => {
                    series.Line(s => s.Volume);
                })
            )
            )
    

Event Handling

You can subscribe to all StockChart events.

By Handler Name

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

Example

        <%: Html.Kendo().StockChart(Model)
                .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(e => e
                    .DataBound("stockChart_dataBound")
                    .SeriesClick("stockChart_seriesClick")
                )
        %>

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

            function stockChart_seriesClick() {
                //Handle the series click event.
            }
        </script>

        @(Html.Kendo().StockChart(Model)
            .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(e => e
              .DataBound("stockChart_dataBound")
              .SeriesClick("stockChart_seriesClick")
            )
        )

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

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

By Template Delegate

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

Example

        @(Html.Kendo().StockChart(Model)
            .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(e => e
              .DataBound(@<text>
                   function() {
                       //Handle the dataBound event inline.
                   }
              </text>)
              .SeriesClick(@<text>
                   function() {
                       //Handle the seriesClick event inline.
                   }
              </text>)
            )
        )

Reference

Existing Instances

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

Example
  //Put this after your Kendo UI StockChart for ASP.NET MVC declaration.
  <script>
      $(function() {
          //Notice that the Name() of the StockChart is used to get its client-side instance.
          var chart = $("#stockChart").data("kendoStockChart");
      });
  </script>

See Also