|
|
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 PieSemiCircle()
{
List<PieSeriesData> pieData = new List<PieSeriesData>();
pieData.Add(new PieSeriesData { Name = "FireFox", Y = 45.0 });
pieData.Add(new PieSeriesData { Name = "IE", Y = 26.8 });
pieData.Add(new PieSeriesData { Name = "Chrome", Y = 12.8, Sliced = true, Selected = true });
pieData.Add(new PieSeriesData { Name = "Safari", Y = 8.5 });
pieData.Add(new PieSeriesData { Name = "Opera", Y = 6.2 });
pieData.Add(new PieSeriesData { Name = "Others", Y = 0.7 });
ViewData["pieData"] = pieData;
return View();
}
}
}
Controller Code
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
@using System.Collections
@{ var chartOptions =
new Highcharts
{
Chart = new Highsoft.Web.Mvc.Charts.Chart
{
PlotBackgroundColor = null,
PlotBorderWidth = 0,
PlotShadow = new Shadow
{
Enabled = false
}
},
Title = new Title
{
Text = "Browser<br>shares<br>2015",
Align = TitleAlign.Center,
VerticalAlign = TitleVerticalAlign.Middle,
Y = 40
},
Tooltip = new Tooltip
{
PointFormat = "{series.name}: <b>{point.percentage:.1f}%</b>"
},
PlotOptions = new PlotOptions
{
Pie = new PlotOptionsPie
{
DataLabels = new Hashtable { { "enabled", true }, { "distance", -50 }, { "color", "#FFFFFF" },
{ "shadow", new Hashtable { {"enabled", true }, { "width", 10 }, { "color", "#000000" }, { "offsetX", 0 }, { "OffsetY", 0 } } }
},
StartAngle = -90,
EndAngle = 90,
Center = new string[] { "50%", "75%" }
}
},
Series = new List<Series>
{
new PieSeries
{
Name = "Browser Share",
InnerSize = "50%",
Data = @ViewData["pieData"] as List<PieSeriesData>
},
}
};
chartOptions.ID = "chart";
var renderer = new HighchartsRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())