Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Chart Control Question

Posted on 2012-03-28
1
Medium Priority
?
576 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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