|
![]() |
Controller Code
using Highsoft.Web.Mvc.Stocks;
using MVC_Demo.Models;
using System;
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 YAxisPlotlines()
{
List<LineSeriesData> currencyData = new List<LineSeriesData>();
double? minRate = 0;
double? maxRate = 1;
using (var db = new HighstockDataEntities())
{
foreach (Flag flag in db.Flags)
{
currencyData.Add(new LineSeriesData
{
Y = Convert.ToDouble(flag.Value),
X = Convert.ToDouble(flag.Date)
}
);
}
minRate = db.Flags.Min(f => f.Value);
maxRate = db.Flags.Max(f => f.Value);
}
ViewBag.Min = minRate;
ViewBag.Max = maxRate;
ViewBag.CurrencyData = currencyData.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>
@{ var chartOptions =
new Highstock
{
RangeSelector = new RangeSelector
{
Selected = 4
},
Title = new Title
{
Text = "USD to EUR exchange rate"
},
YAxis = new List<YAxis>
{
new YAxis
{
Title = new YAxisTitle
{
Text = "Exchange rate"
},
PlotLines = new List<YAxisPlotLines>
{
new YAxisPlotLines
{
Value = ViewBag.Min,
Color = "green",
DashStyle = YAxisPlotLinesDashStyle.ShortDash,
Width = 2,
Label = new YAxisPlotLinesLabel
{
//Text = "Last quarter minimum"
}
},
new YAxisPlotLines
{
Value = ViewBag.Max,
Color = "red",
DashStyle = YAxisPlotLinesDashStyle.ShortDash,
Width = 2,
Label = new YAxisPlotLinesLabel
{
//Text = "Last quarter maximum"
}
}
}
},
},
Series = new List<Series>
{
new LineSeries
{
Data = ViewBag.CurrencyData as List<LineSeriesData>,
Name = "USD to EUR",
Id = "currency",
Tooltip = new LineSeriesTooltip
{
ValueDecimals = 2
}
}
},
PlotOptions = new PlotOptions
{
Series = new PlotOptionsSeries
{
TurboThreshold = 5000
}
}
};
chartOptions.ID = "chart";
var renderer = new HighstockRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())