|
|
Controller Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Highsoft.Web.Mvc.Charts;
namespace MVC_Demo.Areas.Highcharts.Controllers.Shared
{
public partial class SharedController : Controller
{
public ActionResult SplinePlotBands()
{
List<double> hValues = new List<double> { 4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1,
7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4,
8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5,
7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2,
3.0, 3.0 };
List<double> vValues = new List<double> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0,
0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3,
3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4 };
List<SplineSeriesData> hData = new List<SplineSeriesData>();
List<SplineSeriesData> vData = new List<SplineSeriesData>();
hValues.ForEach(p => hData.Add(new SplineSeriesData { Y = p }));
vValues.ForEach(p => vData.Add(new SplineSeriesData { Y = p }));
ViewBag.DateUTC = MilliTimeStamp(new System.DateTime(2009, 1, 1, 0, 0, 0));
ViewData["hData"] = hData;
ViewData["vData"] = vData;
return View();
}
}
}
Controller Code
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
@using System.Collections
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
@{ var chartOptions =
new Highcharts
{
Title = new Title
{
Text = "Wind speed during two days"
},
Subtitle = new Subtitle
{
Text = "October 6th and 7th 2009 at two locations in Vik i Sogn, Norway",
},
XAxis = new List<XAxis>
{
new XAxis
{
Type = "datetime"
}
},
YAxis = new List<YAxis>
{
new YAxis
{
Title = new YAxisTitle
{
Text = "Wind speed (m/s)"
},
Min = 0,
MinorGridLineWidth = 0,
GridLineWidth = 0,
AlternateGridColor = null,
PlotBands = new List<YAxisPlotBands>
{
new YAxisPlotBands
{
From = 0.3,
To = 1.5,
Color = "rgba(68, 170, 213, 0.1)",
Label = new YAxisPlotBandsLabel
{
Text = "Light Air",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
},
new YAxisPlotBands
{
From = 1.1,
To = 3.3,
Color = "rgba(0, 0, 0, 0)",
Label = new YAxisPlotBandsLabel
{
Text = "Light Breeze",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
},
new YAxisPlotBands
{
From = 3.3,
To = 5.5,
Color = "rgba(68, 170, 213, 0.1)",
Label = new YAxisPlotBandsLabel
{
Text = "Gentle breeze",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
},
new YAxisPlotBands
{
From = 5.5,
To = 8,
Color = "rgba(0, 0, 0, 0)",
Label = new YAxisPlotBandsLabel
{
Text = "Moderate breeze",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
},
new YAxisPlotBands
{
From = 8,
To = 11,
Color = "rgba(68, 170, 213, 0.1)",
Label = new YAxisPlotBandsLabel
{
Text = "Fresh breeze",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
},
new YAxisPlotBands
{
From = 11,
To = 14,
Color = "rgba(0, 0, 0, 0)",
Label = new YAxisPlotBandsLabel
{
Text = "Strong breeze",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
},
new YAxisPlotBands
{
From = 14,
To = 15,
Color = "rgba(68, 170, 213, 0.1)",
Label = new YAxisPlotBandsLabel
{
Text = "High wind",
Style = new Hashtable
{
{ "color", "#606060" }
}
}
}
}
}
},
Tooltip = new Tooltip
{
ValueSuffix = "m/s"
},
Legend = new Legend
{
Layout = LegendLayout.Vertical,
Align = LegendAlign.Right,
VerticalAlign = LegendVerticalAlign.Middle,
BorderWidth = 0
},
PlotOptions = new PlotOptions
{
Spline = new PlotOptionsSpline
{
LineWidth = 4,
States = new PlotOptionsSplineStates
{
Hover = new PlotOptionsSplineStatesHover
{
LineWidth = 5
}
},
Marker = new PlotOptionsSplineMarker
{
Enabled = false
},
PointInterval = 3600000,
PointStart = @ViewBag.DateUTC
}
},
Series = new List<Series>
{
new SplineSeries
{
Name = "Hestavollane",
Data = @ViewData["hData"] as List<SplineSeriesData>
},
new SplineSeries
{
Name = "Voll",
Data = @ViewData["vData"] as List<SplineSeriesData>
}
}
};
chartOptions.ID = "chart";
var renderer = new HighchartsRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())