Hi I'm trying to use DotNet HighCharts to create a simple chart to display my ticket sales data in my C# asp.net MVC site. I wish to create a bar/column chart which will show how many tickets in total were available for the event and how many are remaining. I had planned to pass the chart to the view and display it. However my chart is not rendered in my view and I cannot find a reason why it won't display, any help would be greatly appreciated!
This is my controller method
[Authorize(Roles = "canEdit")]
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest)
}
Event events = db.Events.Find(id);
if (events == null)
{
return HttpNotFound();
}
Highcharts chart = new Highcharts("chart")
.SetCredits(new Credits { Enabled = false })
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetTitle(new Title { Text = "Ticket Sales" })
.SetXAxis(new XAxis { Categories = new[] { "Total Tickets", "Tickets Remaining"} })
.SetYAxis(new YAxis
{
Min = 0,
Title = new YAxisTitle { Text = "Quantity" }
})
.SetTooltip(new Tooltip { Formatter = "function() { return ''+ this.series.name +': '+ this.y +''; }" })
.SetPlotOptions(new PlotOptions { Bar = new PlotOptionsBar { Stacking = Stackings.Normal } })
.SetSeries(new[]
{
new Series { Name = "Total", Data = new Data(new object[] { events.TicketsAvailable, events.TicketsRemaining }) }
});
return View(chart);
}
And this is my view
@model DotNet.Highcharts.Highcharts
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<head>
<script src="~/Scripts/jquery-2.1.3.min.js"></script>
<script src="~/Scripts/Highcharts-4.0.1/js/highcharts.js"></script>
<title>Event Title</title>
</head>
<body>
<p>Chart Displaying Ticket Sales </p>
<div>@(Model)</div>
<div>
@Html.ActionLink("Back to List", "Index", "EventsAdmin")
</div>
</body>