Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
SolvedPrivate

Chart Helper With LINQ

Posted on 2014-01-25
3
Medium Priority
?
64 Views
Last Modified: 2016-02-10
Hi Experts!

Trying to use MVC (Razor) with Chart Helper:

http://www.asp.net/web-pages/tutorials/data/7-displaying-data-in-a-chart

Have seen this example:
@{
    var db = Database.Open("SmallBakery");
    var data = db.Query("SELECT Name, Price FROM Product");
    var myChart = new Chart(width: 600, height: 400)
        .AddTitle("Product Sales")
        .DataBindTable(dataSource: data, xField: "Name")
        .Write();
}

Open in new window


Want to incoroprate LINQ so tried this and some:
@{
MyDB db = new MyDB();

var data = from p in db.Products
            select new
            {
                   Name,
		   Price
            };

var myChart = new Chart(width: 600, height: 400)
    .AddTitle("Product Sales")
    .AddSeries(chartType: "Pie",
        xValue: data, xField: "Name",
        yValues: data, yFields: "Price")
    .Write();
}

Open in new window


It spits out this error:
  Message=Specified method is not supported.
  Source=System.Data.Entity
  StackTrace:
       at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.Reset()
       at System.Web.UI.DataVisualization.Charting.DataPointCollection.DataBindXY(IEnumerable xValue, String xField, IEnumerable yValue, String yFields)
       at System.Web.Helpers.Chart.ApplySeries(Chart chart)
       at System.Web.Helpers.Chart.ExecuteChartAction(Action`1 action)
       at System.Web.Helpers.Chart.GetBytes(String format)
       at System.Web.Helpers.Chart.Write(String format)

Open in new window


Do you have an example or any ideas?

TIA!
0
Comment
Question by:allanau20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 39809340
Try changing your linq query as follows, so all the required data is preloaded before being ploted.

var data = (from p in db.Products
            select new
            {
                   Name,
		   Price
            }).ToList();

Open in new window

0
 
LVL 5

Author Comment

by:allanau20
ID: 39809345
Thank you.I'll try it once I get home.
0
 
LVL 5

Author Comment

by:allanau20
ID: 39809381
perfect!
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question