Dotnet Highchart in MVC
Now I am working on a Asp.net MVC4 application, I would like to display
graphs which represents some calculations from the database using LINQ
queries and highcharts.
I can display the graph in my application but without any filter In my
action method I have the following code:
public ActionResult Index()
{
//XAxis : Categories
var item = (from o in frh.Dates
orderby o.Date1
select o.mois).ToArray();
int lenght = item.Count();
string[] data = new string[lenght];
object[] data2 = new object[lenght];
double?[] last = new double?[lenght];
// liste des mois -- string
for (int i = 0; i < lenght; i++)
{
data[i] = item[i].ToString();
}
var items = (from x in frh.productivites
where x.Activité == ***Parameter from view ???***
select new { x.delta_, x.tempstot_, x.mois });
var j = 0;
foreach (var a in data)
{
var sumd = items.Where(c => c.mois == a).Select(c =>
c.delta_).Sum();
var sumt = items.Where(c => c.mois == a).Select(c =>
c.tempstot_).Sum();
var prod = sumd / sumt;
last[j] = prod;
j++;
sumd = 0;
sumt = 0;
prod = 0;
}
data2 = last.Cast<object>().ToArray();
DotNet.Highcharts.Highcharts chart = new
DotNet.Highcharts.Highcharts("chart")
.SetXAxis(new XAxis
{
Categories = data
})
.SetYAxis(new YAxis
{
PlotLines = new[]
{
new YAxisPlotLines
{
Value = 0,
Width = 1,
Color =
ColorTranslator.FromHtml("#808080")
}
}
})
.SetTitle(new Title
{
X = -20
})
.SetSubtitle(new Subtitle
{
X = -20
})
.SetSeries(new Series
{
Data = new Data(data2)
});
return View(chart);
}
I need to pass some fields from view to controller so that I can filter
the json request
how can i do that?? Thank you in advance!
No comments:
Post a Comment