I got solutions for my issue. The solution is given below....
I have created a database with 2 tables called Users and Countries. Now I want to generate a graph on How many users are there in each countries. For this I assigned the Users at Y-Axis and Countries are at X-Axis. Code is below here I create a method called Graph() to generate the graph
My Controller is:
----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Helpers;
using Carrots.Web.Models;
namespace Carrots.Web.Controllers
{
public class ReportSystemController : Controller
{
private DatabaseContext db = new DatabaseContext();
public ActionResult Index()
{
return View();
}
public ActionResult Graph()
{
var countries = db.Countries.ToList();
List<string> countryNames = new List<string>();
List<string> countryUsers = new List<string>();
int cu = -1;
foreach (Country country in countries)
{
countryNames.Add(country.Name);
cu = (from x in db.Users
where x.CountryID == country.CountryID
select x).Count();
countryUsers.Add(cu.ToString());
}
var bytes = new Chart(width: 600, height: 400)
.AddSeries(
chartType: "Column",
legend: "Country vs User",
xValue: countryNames.ToArray(),
yValues: countryUsers.ToArray())
.GetBytes("png");
return File(bytes, "image/png");
}
}
}
And my View is :
--------------------------
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2> Analysis in Graphs </h2>
<p>
<%:Html.ActionLink("No of Recipients received an offer", "Graph")%>       
</p>
</asp:Content>
I think this will help you.....
Ravinderk, if this helps please login to Mark As Answer. | Alert Moderator