Solved

ASP.NET Chart Control Question

Posted on 2012-03-28
1
551 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
1 Comment
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now