ASP.NET MVC StockChart Overview
The Telerik UI StockChart HtmlHelper for ASP.NET MVC is a server-side wrapper 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 MVC 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.
New to Telerik UI for ASP.NET MVC?
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:
- Candlestick
- Open-high-low-close (OHLC)
- Column
- Line
- Area
Basic Configuration
When the StockChart is configured for remote data binding, it makes AJAX requests to the specified Read
endpoint.
The following example demonstrates a basic StockChart configuration with a DataSource, which requests the data from the server.
@(Html.Kendo().StockChart<Kendo.Mvc.Examples.Models.StockDataPoint>()
.Name("stockChart")
.DataSource(ds => ds.Read(read => read
.Action("_StockData", "Home")
))
.DateField("Date")
.Series(series =>
{
series.Candlestick(s => s.Open, s => s.High, s => s.Low, s => s.Close);
})
)
public ActionResult Index()
{
return View(); // The Action that returns the View with the StockChart.
}
public ActionResult _StockData()
{
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(),
JsonRequestBehavior.AllowGet
);
}
}
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; }
}
The Navigator of the StockChart represents a pane that renders at the bottom of the chart that changes the date interval in the main pane. You can drag or scroll the Navigator to select the desired date range.
The following example shows how to enable and configure the Navigator of the chart.
@(Html.Kendo().StockChart<Kendo.Mvc.Examples.Models.StockDataPoint>()
.Name("stockChart")
.DataSource(ds => ds.Read(read => read
.Action("_StockData", "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.Area(s => s.Close); // Specify the field that holds the series data for the Navigator.
})
.Select( // Specifies the initially selected date range.
DateTime.Parse("2009/02/05"),
DateTime.Parse("2011/10/07")
)
)
)
Functionality and Features
- Data Binding—You can bind the StockChart to local or remote data.
- Multiple Panes—Configure the StockChart with multiple panes.
- PDF Export—Export the StockChart to PDF.
- Events—Subscribe to the available client events and implement any custom logic.