|
![]() |
Controller Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVC_Demo.Areas.Highcharts.Controllers.Shared
{
public partial class SharedController : Controller
{
public ActionResult GaugeActivity()
{
return View();
}
}
}
Controller Code
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/solid-gauge.js"></script>
@using System.Collections
<script type="text/javascript">
function getPosition(labelWidth) {
return {
x: 200 - labelWidth / 2,
y: 180
};
}
</script>
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
@{ var chartOptions = new Highcharts
{
Chart = new Highsoft.Web.Mvc.Charts.Chart
{
Type = ChartType.Solidgauge,
MarginTop = 50
},
Title = new Title
{
Text = "Activity"
},
Tooltip = new Tooltip
{
BorderWidth = 0,
BackgroundColor = "none",
Shadow = new Shadow { Enabled = false },
Style = new Hashtable { { "fontSize", "16px" } },
PointFormat = "{series.name}<br><span style=\"font - size:2em; color: { point.color}; font - weight: bold\">{point.y}%</span>",
Positioner = "getPosition"
},
Pane = new Pane
{
StartAngle = 0,
EndAngle = 360,
Background = new List<PaneBackground>
{
new PaneBackground
{
OuterRadius = "112%",
InnerRadius = "88%",
BackgroundColor = new
{
Stops = new List<Stop>
{
new Stop
{
Position = 0,
Color = "rgba(47,126,216,0.3)"
}
}
},
BorderWidth = 0
},
new PaneBackground
{
OuterRadius = "87%",
InnerRadius = "63%",
BackgroundColor = new
{
Stops = new List<Stop>
{
new Stop
{
Position = 0,
Color = "rgba(13,35,58,0.3)"
}
}
},
BorderWidth = 0
},
new PaneBackground
{
OuterRadius = "62%",
InnerRadius = "38%",
BackgroundColor = new
{
Stops = new List<Stop>
{
new Stop
{
Position = 0,
Color = "rgba(139,188,33,0.3)"
}
}
},
BorderWidth = 0
}
}
},
YAxis = new List<YAxis>
{
new YAxis
{
Min = 0,
Max = 100,
LineWidth = 0,
TickPosition = YAxisTickPosition.Outside
}
},
PlotOptions = new PlotOptions
{
Solidgauge = new PlotOptionsSolidgauge
{
DataLabels = new PlotOptionsSolidgaugeDataLabels
{
Enabled = false
},
Linecap = PlotOptionsSolidgaugeLinecap.Round,
StickyTracking = false,
Rounded = true
}
},
Series = new List<Series>
{
new GaugeSeries
{
Name = "Move",
Data = new List<GaugeSeriesData>
{
new GaugeSeriesData
{
Color = "#2f7ed8",
Y = 80
}
}
},
new GaugeSeries
{
Name = "Exercise",
Data = new List<GaugeSeriesData>
{
new GaugeSeriesData
{
Color = "#0d233a",
Y = 65
}
}
},
new GaugeSeries
{
Name = "Stand",
Data = new List<GaugeSeriesData>
{
new GaugeSeriesData
{
Color = "#8bbc21",
Y = 50
}
}
}
}
};
chartOptions.ID = "chart";
var renderer = new HighchartsRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())