1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Data;
#if SILVERLIGHT
using SelectionChangedEventArgs = Telerik.Windows.Controls.SelectionChangedEventArgs;
#endif
namespace RadControlsWpfApp22
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private List<GDPData> Data
{
get
{
List<GDPData> gdpData = new List<GDPData>();
gdpData.Add(new GDPData("Philosophy", 18387785));
gdpData.Add(new GDPData("French", 4910692));
gdpData.Add(new GDPData("English", 1676586));
gdpData.Add(new GDPData("Hist. & Geo.", 1601964));
gdpData.Add(new GDPData("Mathematics", 2866951));
gdpData.Add(new GDPData("Physic & Chimistry", 14441425));
gdpData.Add(new GDPData("Life and Soil Sc.", 3673105));
gdpData.Add(new GDPData("Artistic Edu.", 2313893));
gdpData.Add(new GDPData("Computer Sc.", 4327448));
gdpData.Add(new GDPData("P.S.T.", 2680000));//Physical and Sporting Tests
return gdpData;
}
}
public MainWindow()
{
InitializeComponent();
CountriesBox.ItemsSource = this.Data;
this.ConfigureChart();
}
private void ConfigureChart()
{
RadChart1.DefaultView.ChartTitle.Content = "Top 10 Countries by GDP 2008 (nominal)";
RadChart1.DefaultSeriesDefinition.ShowItemToolTips = true;
RadChart1.DefaultSeriesDefinition.ItemToolTipFormat = "#Y{C0} million";
RadChart1.DefaultView.ChartArea.AxisY.Title = "GDP (mil USD)";
RadChart1.DefaultView.ChartArea.EnableAnimations = false;
RadChart1.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
SeriesMapping gdpSeriesMapping = new SeriesMapping();
gdpSeriesMapping.LegendLabel = "GDP (millions of USD)";
gdpSeriesMapping.ItemMappings.Add(new ItemMapping("Country", DataPointMember.XCategory));
gdpSeriesMapping.ItemMappings.Add(new ItemMapping("GDP", DataPointMember.YValue));
gdpSeriesMapping.ItemMappings.Add(new ItemMapping("Country", DataPointMember.LegendLabel));
RadChart1.SeriesMappings.Add(gdpSeriesMapping);
RadChart1.ItemsSource = this.Data;
}
private void SortSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RadChart1 == null || SortGDP == null || SortCountry == null)
return;
RadChart1.SortDescriptors.SuspendNotifications();
RadChart1.SortDescriptors.Clear();
string sortByCountry = (SortCountry.SelectedValue as RadComboBoxItem).Content as string;
string sortByGDP = (SortGDP.SelectedValue as RadComboBoxItem).Content as string;
this.ApplySorting(sortByCountry, "Country");
this.ApplySorting(sortByGDP, "GDP");
RadChart1.SortDescriptors.ResumeNotifications();
}
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
CheckBox sourceCheckbox = e.OriginalSource as CheckBox;
Queue<ChartFilterDescriptor> filtersToRemove = new Queue<ChartFilterDescriptor>();
foreach (ChartFilterDescriptor descriptor in RadChart1.FilterDescriptors)
{
if (descriptor.Value.Equals(sourceCheckbox.Content))
filtersToRemove.Enqueue(descriptor);
}
foreach (ChartFilterDescriptor descriptor in filtersToRemove)
RadChart1.FilterDescriptors.Remove(descriptor);
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
CheckBox sourceCheckbox = e.OriginalSource as CheckBox;
RadChart1.FilterDescriptors.Add(new ChartFilterDescriptor("Country", typeof(string), FilterOperator.IsNotEqualTo, sourceCheckbox.Content));
}
private void ApplySorting(string sortDirection, string fieldName)
{
if (sortDirection.ToLower() != "none")
{
if (sortDirection.ToLower() == "asc")
RadChart1.SortDescriptors.Add(new ChartSortDescriptor(fieldName, ListSortDirection.Ascending));
else
RadChart1.SortDescriptors.Add(new ChartSortDescriptor(fieldName, ListSortDirection.Descending));
}
}
public class GDPData
{
private string _country;
private decimal _gdp;
public string Country
{
get
{
return this._country;
}
set
{
this._country = value;
}
}
public decimal GDP
{
get
{
return this._gdp;
}
set
{
this._gdp = value;
}
}
public GDPData(string country, decimal gdp)
{
this.GDP = gdp;
this.Country = country;
}
}
}
} |
Partager