DotNet Highcharts Example in Asp.Net MVC

 

http://www.howstat.com/cricket/Statistics/Players/PlayerYears_ODI.asp?PlayerID=1735

http://www.howstat.com/cricket/Statistics/Players/PlayerYears_ODI.asp?PlayerID=3243

https://github.com/fairmat/DotNet.Highcharts/blob/master/DotNet.Highcharts/DotNet.Highcharts.Samples/Controllers/DemoController.cs

http://www.pardesiservices.com/softomatix/colorchart.asp

 

using DotNet.Highcharts;
using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HighchartsWithMVC.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            List<Highcharts> chartList = new List<Highcharts>();

            //Column Chart Example
            Highcharts columnChart = new Highcharts("columnchart");            

            columnChart.InitChart(new Chart()
            {
                Type = DotNet.Highcharts.Enums.ChartTypes.Column,
                BackgroundColor = new BackColorOrGradient(System.Drawing.Color.AliceBlue),                
                Style = "fontWeight: 'bold', fontSize: '17px'",
                BorderColor = System.Drawing.Color.LightBlue,
                BorderRadius = 0,
                BorderWidth =2

            });

            columnChart.SetTitle(new Title()
            {
                Text = "Sachin Vs Dhoni"
            });

            columnChart.SetSubtitle(new Subtitle()
            {
                Text = "Played 9 Years Together From 2004 To 2012"
            });

            columnChart.SetXAxis(new XAxis()
            {
                Type = AxisTypes.Category,                
                Title = new XAxisTitle() { Text = "Years", Style = "fontWeight: 'bold', fontSize: '17px'" },
                Categories = new[] { "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012" }
            });

            columnChart.SetYAxis(new YAxis()
            {
                Title = new YAxisTitle()
                {
                    Text = "Runs",
                    Style = "fontWeight: 'bold', fontSize: '17px'"
                },
                ShowFirstLabel = true,
                ShowLastLabel = true,
                Min = 0
            });

            columnChart.SetLegend(new Legend {
                Enabled = true,
                BorderColor = System.Drawing.Color.CornflowerBlue,
                BorderRadius = 6,
                BackgroundColor= new BackColorOrGradient(ColorTranslator.FromHtml("#FFADD8E6"))                
            });

            columnChart.SetSeries(new Series[]
            {
                new Series{

                    Name = "Sachin Tendulkar",
                    Data = new Data(new object[] { 812, 412, 628, 1425, 460, 972, 204, 513, 315 })
                },
                new Series()
                {
                    Name = "M S Dhoni",
                    Data = new Data(new object[] { 19, 895, 821, 1103, 1097, 1198, 600, 764, 524, })
                }
            }
            );

            chartList.Add(columnChart);
            return View(chartList);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
@model List<DotNet.Highcharts.Highcharts>

@{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
  <h3>DotNet Highcharts Example in Asp.Net MVC</h3>
  <p><a href="http://dotnet.highcharts.com/" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

<div class="row">
  <div>
    @foreach (var item in Model)
    {
        <div class="col-md-12 col-md-6">
          @(item)
        </div>
    }
  </div>
</div>