|
|
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 Polar()
{
return View();
}
}
}
Controller Code
<script src="https://code.highcharts.com/highcharts.js"></script>
@*The highchart-more.js file contains definitions for additional chart types not available
in the main highcharts.js file such as "arearange". You need to include this file if you
are using these types of charts*@
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
<script type="text/javascript">
function formatXAxisLabels() {
return this.value + '°';
}
</script>
@{ var chartOptions =
new Highcharts
{
Chart = new Highsoft.Web.Mvc.Charts.Chart
{
Polar = true
},
Title = new Title
{
Text = "Highcharts Polar Chart"
},
Pane = new Pane
{
StartAngle = 0,
EndAngle = 360
},
XAxis = new List<XAxis>
{
new XAxis
{
TickInterval = 45,
Min = 0,
Max = 360,
Labels = new XAxisLabels
{
Formatter = "formatXAxisLabels"
}
}
},
YAxis = new List<YAxis>
{
new YAxis
{
Min = 0
}
},
PlotOptions = new PlotOptions
{
Series = new PlotOptionsSeries
{
PointStart = 0,
PointInterval = 45
},
Column = new PlotOptionsColumn
{
PointPadding = 0,
GroupPadding = 0
}
},
Series = new List<Series>
{
new ColumnSeries
{
Name = "Column",
PointPlacement = new PointPlacement
{
PointPlacementEnum = PointPlacementEnum.Between
},
Data = new List<ColumnSeriesData> {
new ColumnSeriesData { Y = 8 },
new ColumnSeriesData { Y = 7 },
new ColumnSeriesData { Y = 6 },
new ColumnSeriesData { Y = 5 },
new ColumnSeriesData { Y = 4 },
new ColumnSeriesData { Y = 3 },
new ColumnSeriesData { Y = 2 },
new ColumnSeriesData { Y = 1 }
}
},
new LineSeries
{
Name = "Line",
Data = new List<LineSeriesData> {
new LineSeriesData { Y = 1 },
new LineSeriesData { Y = 2 },
new LineSeriesData { Y = 3 },
new LineSeriesData { Y = 4 },
new LineSeriesData { Y = 5 },
new LineSeriesData { Y = 6 },
new LineSeriesData { Y = 7 },
new LineSeriesData { Y = 8 }
}
},
new AreaSeries
{
Name = "Area",
Data = new List<AreaSeriesData> {
new AreaSeriesData { Y = 1 },
new AreaSeriesData { Y = 8 },
new AreaSeriesData { Y = 2 },
new AreaSeriesData { Y = 7 },
new AreaSeriesData { Y = 3 },
new AreaSeriesData { Y = 6 },
new AreaSeriesData { Y = 4 },
new AreaSeriesData { Y = 5 }
}
}
}
};
chartOptions.ID = "chart";
var renderer = new HighchartsRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())