?
Solved

ASP.NET Chart Control Question

Posted on 2012-03-28
1
Medium Priority
?
570 Views
Last Modified: 2012-06-21
Hello,

I've got a large linq query that populates a report (.rdlc file) in a ReportViewer control.  I would like to use this linq query to populate an ASP.NET (C#.NET 4.0) chart control as well.  

The problem is that the chart is not rendering the data correctly, due to the linq query returning a dataset containing one item per row instead of a dataset that is grouped (example below).  I set one column for the X-Axis on the report and one column for the Y-Axis.  What I really need, however is to set the column to SUM or .Count().  

Example:

Column #1:  DateVisited (datetime)
Column #2:  UserName (string)

I need for Column #1 (date visited) to be on the X-Axis of the chart (one tick per day).
I need for Column #2 (UserName) to sum, so that if 5 separate users visited the website 5 times in a day, then the chart would say that there were 25 visits (5x5=25).

Is there a way to tell the chart to sum a column, or will I just have to write a separate linq query for the chart that does this?

Thank you in advance.
0
Comment
Question by:adskarcox
[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
1 Comment
 
LVL 13

Accepted Solution

by:
Rahul Agarwal earned 1500 total points
ID: 37780363
protected override void CustomizeChartSeries(IList<Series> seriesList) {
    var repository = FlightRepositoryFactory.CreateRepository();
    var query = repository.Flights
                          .GroupBy(flight => flight.Destination)
                          .OrderByDescending(group => group.Count())
                          .Take(5);
    Series cities = seriesList.Single();
    cities.Name = "Cities";
    foreach (var record in query) {
        cities.Points.AddXY(record.Key, record.Count());
    }
}


Reference:

http://msdn.microsoft.com/en-us/magazine/dd453008.aspx
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

771 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