|
![]() |
Controller Code
using Highsoft.Web.Mvc.Stocks;
using MVC_Demo.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace MVC_Demo.Areas.Highstock.Controllers.Shared
{
public partial class SharedController : Controller
{
public ActionResult Candlestick()
{
List<CandleStickSeriesData> appleData = new List<CandleStickSeriesData>();
List<LineSeriesData> navigatorData = new List<LineSeriesData>();
foreach (CandlestickVolume data in DataReceiver.GetJSONCandlestickVolumes())
{
appleData.Add(new CandleStickSeriesData
{
X = Convert.ToDouble(data.Date),
High = Convert.ToDouble(data.High),
Low = Convert.ToDouble(data.Low),
Open = Convert.ToDouble(data.Open),
Close = Convert.ToDouble(data.Close)
});
navigatorData.Add(new LineSeriesData
{
X = Convert.ToDouble(data.Date),
Y = Convert.ToDouble(data.Close)
});
}
ViewBag.AppleData = appleData.OrderBy(o => o.X).ToList();
ViewBag.NavigatorData = navigatorData.OrderBy(o => o.X).ToList();
return View(ViewBag);
}
}
}
Controller Code
@using Highsoft.Web.Mvc.Stocks
@using Highsoft.Web.Mvc.Stocks.Rendering
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
function formatYAxis() {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
</script>
@{ var chartOptions =
new Highstock
{
Chart = new Highsoft.Web.Mvc.Stocks.Chart
{
Type = ChartType.Ohlc
},
RangeSelector = new RangeSelector
{
Selected = 1
},
Title = new Title
{
Text = "Apple Stock Price"
},
Series = new List<Series>
{
new CandleStickSeries
{
Data = ViewBag.AppleData as List<CandleStickSeriesData>,
Name = "Apple Stock Price",
TurboThreshold = 10000,
Shadow = new Shadow
{
Enabled = true,
},
Tooltip = new CandleStickSeriesTooltip
{
ValueDecimals = 2
}
}
},
Navigator = new Navigator()
{
Series = new LineSeries
{
Data = ViewBag.NavigatorData as List<LineSeriesData>
}
}
};
chartOptions.ID = "chart";
var renderer = new HighstockRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())