public PartialViewResult Vote(int pollID, int option) { // default userId to 1 for now Vote vote = new Vote() { PollID = pollID, ChoiceID = option, DateVoted = DateTime.Now, UserID = 2 }; repository.AddVote(vote); // get the count of all votes for the poll Dictionary <string, int> voteDict = new Dictionary <string, int>(); Poll poll = repository.Poll(pollID); foreach (var opt in poll.Options) { int count = repository.GetVotes(pollID, opt.OptionID); voteDict.Add(opt.Text.Replace("'", "\\\'"), count); } string[] keys = voteDict.OrderByDescending(x => x.Value).Select(x => x.Key).ToArray(); int[] values = voteDict.OrderByDescending(x => x.Value).Select(x => x.Value).ToArray(); // now we have the votes for each option DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart") .SetTitle(new DotNet.Highcharts.Options.Title { Text = poll.PollQuestion }) .SetXAxis(new DotNet.Highcharts.Options.XAxis { Categories = keys }) .SetSeries(new DotNet.Highcharts.Options.Series { Type = DotNet.Highcharts.Enums.ChartTypes.Bar, Name = "Votes", Data = new DotNet.Highcharts.Helpers.Data(Array.ConvertAll(values, x => (object)x)) }); //chart.SetTooltip(new DotNet.Highcharts.Options.Tooltip //{ // UseHTML = true, // HeaderFormat = "<span>Those who voted</span><table>", // PointFormat = "<tr><td style" //}); return(PartialView("_PollResults", chart)); }