Reputation: 495
I have the code below, run it in LinqPad 4.40.03 + Sql Server 2008 R2 + NorthWind.
LinqPad return exception: "ArgumentNullException: Value cannot be null. Parameter name: httpContext".
Please give me the Final Fixed code, I want it populate a chart ( Using System.Web.Helpers.Chart ) in linqpad output screen.
void Main()
{
var q = from p in Products
let s = p.OrderDetails.Sum(o => o.Quantity) * p.UnitPrice
orderby s
select new { ProductName = p.ProductName, Sales = s};
var basicChart = new System.Web.Helpers.Chart(width: 600, height: 400)
.AddTitle("Product Sales")
.DataBindTable(dataSource: q, xField: "ProductName")
.Write();
basicChart.Dump();
}
Upvotes: 2
Views: 1217
Reputation: 30994
The ASP.NET charting control relies on HttpContext.Current which is present only when running an ASP.NET application.
You could try mocking an HttpContext, or else use the charting control in System.Windows.Forms.DataVisualization.Charting
instead:
var q = from p in Products
let s = p.OrderDetails.Sum(o => o.Quantity) * p.UnitPrice
orderby s
select new { ProductName = p.ProductName, Sales = s};
var chart = new Chart();
var ca = new ChartArea();
ca.AxisX.LabelStyle.Interval = 1;
chart.ChartAreas.Add (ca);
var series = new Series { ChartType = SeriesChartType.Bar};
series.Points.DataBind (q.Take(20), "ProductName", "Sales", null);
chart.Series.Add (series);
chart.Dump ("Chart");
Upvotes: 7