Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my WPF application, I have a following query to display the selected date range as 'Date' and total number of servers being processed on each day as 'Amount'.

var query_1 = 
      
      (this.db.Servers
      .Where(a => (a.Date >= fromDP.SelectedDate.Value && a.Date <= toDP.SelectedDate.Value)
       && ((a.ServerID == "ServerID1" || a.ServerID == "ServerID2") && a.Type == "Complete"))
      .GroupBy(a => EntityFunctions.TruncateTime(a.Date))
      .OrderBy(a => a.Key)
      .Select(g => new { Date = g.Key, Amount = g.Count() }))
      .ToList();


which returns the output as following - ( kindly check the second link, at the last of the question ending with result1.png)
when bind to a ListBox's ItemsSource ( just to check whether the query works correctly)
Now how to bind this result, **Date** and **Amount** to the WPF chart X and Y axis. ( X- Axis for Date and Y-Axis for Amount).

The chart can be either Bubble Series/Line Series or Column series.

What I have tried

Code Behind

var query_2 = 
      
      (this.db.Servers
      .Where(a => (a.Date >= fromDP.SelectedDate.Value && a.Date <= toDP.SelectedDate.Value)
       && ((a.ServerID == "ServerID1" || a.ServerID == "ServerID2") && a.Type == "Complete"))
      .GroupBy(a => EntityFunctions.TruncateTime(a.Date))
      .OrderBy(a => a.Key)
      .Select(g => new { Date = g.Key }))
      .ToList();var query_1 = 
      
     var query_1 = 
      (this.db.Servers
      .Where(a => (a.Date >= fromDP.SelectedDate.Value && a.Date <= toDP.SelectedDate.Value)
       && ((a.ServerID == "ServerID1" || a.ServerID == "ServerID2") && a.Type == "Complete"))
      .GroupBy(a => EntityFunctions.TruncateTime(a.Date))
      .OrderBy(a => a.Key)
      .Select(g => new { Amount = g.Count() }))
      .First();

      var successBar_Query = new List<Server>() { new Server() { dummy = fromDP.SelectedDate.Value.Date, name = Convert.ToDateTime(query_2.Date) } };

      var failedBar_Query = new List<Server>() { new Server() { name = toDP.SelectedDate.Value.Date, value = query_1.Amount } };

     success_Chart.ItemsSource = successBar_Query.ToList();
     failed_Chart.ItemsSource = failedBar_Query.ToList();



XAML


<dvc:BubbleSeries x:Name="success_Chart"  Margin="10"
          IndependentValuePath="dummy" DependentValuePath="name"
          ItemsSource="{Binding}">
    </dvc:BubbleSeries>
    <dvc:BubbleSeries x:Name="failed_Chart" Margin="10"
       IndependentValuePath="name" DependentValuePath="value"
       ItemsSource="{Binding}">
       </dvc:BubbleSeries>


and this returns the result- http://s10.postimg.org/trwvz00eh/history.png[^]http://s22.postimg.org/svtql2g4x/result1.png[^]
Posted
Updated 5-May-13 21:37pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900