Highcharts is a JavaScript library to implement charting functionality like line chart, bar chart, column chart etc. We can create different types of charts using highcharts. Today with this article, I will try to show you how to create Highcharts in Asp.Net MVC from server side.We see the chart using ASP.NET MVC from the server side. Here, server-side means that everything will be created on the server and only the displaying part will happen at the client side. You can find more details on http://dotnet.highcharts.com/
Step-1: File New Project >> ASP .NET Web application
Choose MVC as application |
You can isntall the package using Nuget Package manager Console also like below;
Install-Package DotNet.Highcharts
Initialize the Chart
Highcharts columnChart = new Highcharts("columnchart");
columnChart.InitChart(new Chart()
{
Type = DotNet.Highcharts.Enums.ChartTypes.Column,
Style = "fontWeight: 'bold', fontSize: '17px'",
Width=900,
BackgroundColor = new BackColorOrGradient(System.Drawing.Color.AliceBlue),
BorderColor = System.Drawing.Color.LightBlue,
BorderRadius = 0,
BorderWidth = 2
});
columnChart.SetTitle(new Title()
{
Text = "Best batting average in successful ODI run-chases"
});
columnChart.SetXAxis(new XAxis()
{
Type = AxisTypes.Category,
Title = new XAxisTitle() { Text = "Batsman",
Style = "fontWeight: 'bold', fontSize: '17px'" },
Categories = new[] { "MS Dhoni", "Virat Kohli", "Michael Bevan", "Dinesh Chandimal", "AB DE Villiers", "Joe Root", "Mike Hussy", "Michael Clarke", "Angelo Mathews", "Graham Thorpe" },
});
columnChart.SetYAxis(new YAxis()
{
Title = new YAxisTitle()
{
Text = "Average Wining Runs",
},
ShowFirstLabel = true,
ShowLastLabel = true,
Min = 0
});
columnChart.SetSeries(new Series[]
{
new Series{
Name = "Wining average",
Data = new Data(new object[] { 99.85,99.04,86.25,85.30,82.77,77.80,74.10,73.86,70.75,70.75 })
},
}
<div class="row">
<div>
<div class="col-md-12 col-md-6">
@(Model)
</div>
</div>
</div>
<script src="~/Scripts/Highcharts-4.0.1/js/highcharts.js"></script>
Please find the Source code in Github
Summary
Post a Comment