|
|
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 Pie3DDonut()
{
List<PieSeriesData> pieData = new List<PieSeriesData>();
pieData.Add(new PieSeriesData { Name = "Bananas", Y = 8 });
pieData.Add(new PieSeriesData { Name = "Kiwi", Y = 3 });
pieData.Add(new PieSeriesData { Name = "Mixed Nuts", Y = 1 });
pieData.Add(new PieSeriesData { Name = "Oranges", Y = 6 });
pieData.Add(new PieSeriesData { Name = "Apples", Y = 8 });
pieData.Add(new PieSeriesData { Name = "Pears", Y = 4 });
pieData.Add(new PieSeriesData { Name = "Cleamentines", Y = 4 });
pieData.Add(new PieSeriesData { Name = "Reddish (bag)", Y = 1 });
pieData.Add(new PieSeriesData { Name = "Grapes (bunch)", Y = 1 });
ViewData["pieData"] = pieData;
return View();
}
}
}
Controller Code
<script src="https://code.highcharts.com/highcharts.js"></script>
@*All Highcharts 3D charts requires the highcharts-3rd.js module*@
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
@{ var chartOptions =
new Highcharts
{
Chart = new Highsoft.Web.Mvc.Charts.Chart
{
Options3d = new ChartOptions3d
{
Enabled = true,
Alpha = 45,
Beta = 0
}
},
Title = new Title
{
Text = "Contents of Highsoft\'s weekly fruit delivery"
},
Subtitle = new Subtitle
{
Text = "3D donut in Highcharts"
},
PlotOptions = new PlotOptions
{
Pie = new PlotOptionsPie
{
InnerSize = "100",
Depth = 45
}
},
Series = new List<Series>
{
new PieSeries
{
Name = "Browser Share",
Data = @ViewData["pieData"] as List<PieSeriesData>
}
}
};
chartOptions.ID = "chart";
var renderer = new HighchartsRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())