Reputation: 5209
I am trying to generate a chart using the MS Chart Control in ASP.NET 4. It's a standard column chart and I'm populating it by databinding a LINQ resultset calling a stored procedure.
The graph is showing number of phone calls over a period of time. It is setup with an XAxis detailing a timespan/date range, and the YAxis detailing call totals.
If the resultset only returns data from one phone number then all is good. However, sometimes I want to return more than one phone number in the same resultset, and show the data using multiple series on the chart, so the columns stand next to each other for comparison over time.
I know that for each phone number I need to have a separate series, and if I populate the data manually, or manually create more than one series as a proof of concept I know it works. But I cannot get it to automatically separate out the phone numbers into individual series.
What I'm looking for is a property to specify the column in the resultset to group the series by, but I can't seem to find it (maybe because it doesn't exist?).
The data looks like this:
row_date call_total ext_no
---------- ---------- ------
2011-01-01 18 1000
2011-02-01 9 1000
2011-03-01 28 1000
2011-01-01 49 1001
2011-02-01 34 1001
2011-03-01 29 1001
Any help?
Upvotes: 1
Views: 5904
Reputation: 5209
Absolutely typical. Once you concede and post the question, it jumps up in front of you.
The answer to this is simple. Instead of databinding my LINQ resultset using
Chart.DataSource = <LINQ QUERY>
Chart.DataBind()
You need to use
Chart.DataBindCrossTable(<LINQ QUERY>,<COL TO GROUP>,<X COL>,<Y COL>)
I (finally) found this buried in this article:
Data Binding Microsoft Chart Control
Upvotes: 3