using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

using C1.Xaml.Chart;

namespace ChartSamples
{
  public sealed partial class AggregateByName : UserControl
  {
      public AggregateByName()
      {
          InitializeComponent();
          CreateSampleChart();
      }

      void CreateSampleChart()
      {
          var keys = new List<string> { "oranges", "apples", "lemons", "grapes" };

          for (int i = 0; i < 2; i++)
          {
              var ds = new DataSeries()
              {
                  ItemsSource = SampleItem.CreateSampleData(40),
                  ValueBinding = new Binding() { Path = new PropertyPath("Value")},
                  Aggregate = Aggregate.Sum,
                  Label = "s" + i
              };
              ds.AggregateGroupSelector = (x, y, o) =>
              {
                  // index from categories list 
                  return keys.IndexOf(((SampleItem)o).Name);
              };

              chart.Data.Children.Add(ds);
          }

          chart.Data.ItemNames = keys;
      }

      private void Button_Click(object sender, RoutedEventArgs e)
      {
          chart.Data.Children.Clear();
          CreateSampleChart();
      }
  }
}
