@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 loadData() {
$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function (data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length,
// set the allowed units for data grouping
groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]],
i = 0;
for (i; i < dataLength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] // the volume
]);
}
var chart = $("#chart").highcharts();
console.log(chart);
//chart.series[0].setData(ohlc);
//chart.series[1].setData(volume);
//window.setTimeout(function () { chart.redraw(); }, 1000);
})
}
</script>
@{ var chartOptions =
new Highstock
{
Chart = new Highsoft.Web.Mvc.Stocks.Chart
{
//Events = new ChartEvents
//{
// Load = "loadData"
//}
},
RangeSelector = new RangeSelector
{
Selected = 1
},
Title = new Title
{
Text = "AAPL Stock Price"
},
YAxis = new List<YAxis>
{
new YAxis
{
Labels = new YAxisLabels
{
Align = YAxisLabelsAlign.Right,
X = -3
},
Title = new YAxisTitle
{
Text = "OHLC"
},
Height = "60%",
LineWidth = 2
},
new YAxis
{
Labels = new YAxisLabels
{
Align = YAxisLabelsAlign.Right,
X = -3
},
Title = new YAxisTitle
{
Text = "Volume"
},
Top = "65%",
Height = "35%",
//Offset = -1,
LineWidth = 2,
Id = "VolumeAxis"
}
},
Series = new List<Series>
{
new CandleStickSeries
{
Data = ViewBag.AppleData as List<CandleStickSeriesData>,
Name = "AAPL",
TurboThreshold = 10000
},
new ColumnSeries
{
Name = "Volume",
Data = ViewBag.VolumeData as List<ColumnSeriesData>,
DataGrouping = new ColumnSeriesDataGrouping() {Enabled = true, Forced = true },
YAxis = "VolumeAxis",
TurboThreshold = 10000,
ShowInNavigator = true
}
}
};
chartOptions.ID = "chart";
var renderer = new HighstockRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())