Solved

ASP.NET Chart Control Question

Posted on 2012-03-28
1
557 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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