private void OnChartTypeSelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; if (Basic_Chart5 == null) { return; } if (comboBox.SelectedIndex == 0 && viewModelColumn != null && viewModelColumn1 != null) { (Basic_Chart5.Legend as ChartLegend).Visibility = Visibility.Visible; Basic_Chart51.Visibility = Visibility.Visible; Basic_Chart5.SetValue(Grid.RowSpanProperty, 1); Basic_Chart5.Axes.Clear(); Basic_Chart51.Axes.Clear(); Basic_Chart5.AreaBorderThickness = new Thickness(1, 0, 0, 1); Basic_Chart5.AreaBorderThickness = new Thickness(1, 0, 0, 1); Basic_Chart5.Height = 257; Basic_Chart5.Width = 894; Basic_Chart51.Height = 257; Basic_Chart51.Width = 894; Basic_Chart5.Header = new TextBlock() { Text = "Literacy rate in Nation", FontWeight = FontWeights.SemiBold }; Basic_Chart51.Header = new TextBlock() { Text = "Economic Growth - Year 2014", FontSize = 20, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(50, 20, 0, 0), FontWeight = FontWeights.Medium, FontFamily = new FontFamily("Segoe UI") }; ColumnSeries series1 = new ColumnSeries(); ColumnSeries series2 = new ColumnSeries(); ColumnSeries series3 = new ColumnSeries(); DataTemplate template1 = MainGrid3.Resources["labelTemplate"] as DataTemplate; DataTemplate template2 = MainGrid3.Resources["headerTemplate"] as DataTemplate; DataTemplate template3 = MainGrid3.Resources["columnnewtemp1"] as DataTemplate; DataTemplate template7 = MainGrid3.Resources["columnnewtemp2"] as DataTemplate; Style template5 = MainGrid3.Resources["axisLineStyle"] as Style; Style template6 = MainGrid3.Resources["minorTickLineStyle"] as Style; DataTemplate template8 = MainGrid3.Resources["columnnewtemp3"] as DataTemplate; DataTemplate template4 = MainGrid3.Resources["postfixTemplatecc"] as DataTemplate; CategoryAxis axis1 = new CategoryAxis() { ShowGridLines = false, LabelPlacement = Syncfusion.UI.Xaml.Charts.LabelPlacement.BetweenTicks, AxisLineStyle = template5, MajorTickLineStyle = template6 }; NumericalAxis axis2 = new NumericalAxis() { ShowGridLines = false, AxisLineStyle = template5, MajorTickLineStyle = template6, PostfixLabelTemplate = template4, Minimum = "0", Maximum = "100", Interval = "20", PlotOffset = 20 }; CategoryAxis axis3 = new CategoryAxis() { ShowGridLines = false, LabelPlacement = Syncfusion.UI.Xaml.Charts.LabelPlacement.BetweenTicks, AxisLineStyle = template5, MajorTickLineStyle = template6 }; NumericalAxis axis4 = new NumericalAxis() { ShowGridLines = false, AxisLineStyle = template5, MajorTickLineStyle = template6, PostfixLabelTemplate = template4, Minimum = "0", Maximum = "30", Interval = "10", PlotOffset = 20 }; series3.XAxis = axis3; series3.YAxis = axis4; Basic_Chart5.PrimaryAxis = axis1; Basic_Chart5.SecondaryAxis = axis2; series3.XBindingPath = "Gadget"; series3.YBindingPath = "Value2"; series3.ItemsSource = viewModelColumn1; series3.LegendIcon = ChartLegendIcon.Rectangle; series3.SegmentSpacing = 0.5; series3.Interior = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xC1, 0x07)); series3.CustomTemplate = template8; series1.XBindingPath = "Gadget"; series1.YBindingPath = "Value1"; series1.Label = "Educated"; series3.Label = "Year 2014"; series2.Label = "Uneducated"; series1.ItemsSource = viewModelColumn; series1.LegendIcon = ChartLegendIcon.Rectangle; series1.Interior = new SolidColorBrush(Color.FromArgb(0xFF, 0x8B, 0xC3, 0x4A)); series2.Interior = new SolidColorBrush(Color.FromArgb(0xFF, 0xD1, 0xD3, 0xD4)); series1.CustomTemplate = template3; series2.LegendIcon = ChartLegendIcon.Rectangle; series2.XBindingPath = "Gadget"; series2.YBindingPath = "Value1"; series2.ItemsSource = viewModelColumn; series2.CustomTemplate = template7; Basic_Chart5.Series.Clear(); Basic_Chart51.Series.Clear(); Basic_Chart5.Series.Add(series1); Basic_Chart5.Series.Add(series2); Basic_Chart51.Series.Add(series3); } else if (comboBox.SelectedIndex == 2 && viewModelScatter != null) { Basic_Chart51.Visibility = Visibility.Collapsed; (Basic_Chart5.Legend as ChartLegend).Visibility = Visibility.Collapsed; Basic_Chart5.SetValue(Grid.RowSpanProperty, 2); Basic_Chart5.Axes.Clear(); Basic_Chart51.Axes.Clear(); Basic_Chart51.Series.Clear(); Basic_Chart5.Header = new TextBlock() { Text = "Global Stock Trend Comparison (2013 - 2014)", Margin = new Thickness(50, 10, 0, 10), FontSize = 20, FontWeight = FontWeights.SemiBold }; Basic_Chart5.AreaBorderThickness = new Thickness(0, 0.5, 0.5, 0); Basic_Chart5.Height = 515; Basic_Chart5.AreaBorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD1, 0xD3, 0xD4)); DataTemplate template1 = MainGrid3.Resources["scattertemplate"] as DataTemplate; DataTemplate template2 = MainGrid3.Resources["scatterAdornmentTemplate"] as DataTemplate; ChartAdornmentInfo adornmentInfo1 = new ChartAdornmentInfo(); DataTemplate template3 = MainGrid3.Resources["labelTemplate"] as DataTemplate; DataTemplate template4 = MainGrid3.Resources["headerTemplate"] as DataTemplate; Style axisstyle = MainGrid3.Resources["axisLineStyle"] as Style; Style ticklinestyle = MainGrid3.Resources["minorTickLineStyle"] as Style; DateTimeAxis axis1 = new DateTimeAxis() { PlotOffset = 30, Interval = 1, IntervalType = DateTimeIntervalType.Months, LabelFormat = "MMM", Header = "Year 2014", LabelTemplate = template3, HeaderTemplate = template4, AxisLineStyle = axisstyle, MajorTickLineStyle = ticklinestyle, ShowGridLines = false }; NumericalAxis axis2 = new NumericalAxis() { Minimum = 10, Maximum = 80, Interval = 10, Header = "Stock Price", LabelFormat = "$0", LabelTemplate = template3, HeaderTemplate = template4, AxisLineStyle = axisstyle, MajorTickLineStyle = ticklinestyle, }; ScatterSeries series = new ScatterSeries(); adornmentInfo1.ShowLabel = true; adornmentInfo1.SegmentLabelContent = LabelContent.LabelContentPath; adornmentInfo1.LabelTemplate = template2; series.XBindingPath = "Year"; series.YBindingPath = "Count"; series.CustomTemplate = template1; series.YAxis = axis2; series.XAxis = axis1; series.ItemsSource = viewModelScatter; series.ScatterWidth = 64; series.ScatterHeight = 64; series.AdornmentsInfo = adornmentInfo1; Basic_Chart5.Series.Clear(); Basic_Chart5.Series.Add(series); } else if (comboBox.SelectedIndex == 3 && viewModelSpline != null) { Basic_Chart51.Visibility = Visibility.Collapsed; (Basic_Chart5.Legend as ChartLegend).Visibility = Visibility.Collapsed; Basic_Chart5.SetValue(Grid.RowSpanProperty, 2); Basic_Chart5.Axes.Clear(); Basic_Chart51.Axes.Clear(); Basic_Chart51.Series.Clear(); Basic_Chart5.Height = 515; Basic_Chart5.Header = new TextBlock() { Text = "Climate Graph", Margin = new Thickness(50, 10, 0, 10), FontSize = 20, FontWeight = FontWeights.SemiBold }; Basic_Chart5.AreaBorderThickness = new Thickness(1, 1, 1, 1); Basic_Chart5.AreaBorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD1, 0xD3, 0xD4)); Basic_Chart5.AreaBorderThickness = new Thickness(0, 0.5, 0.5, 0); SplineSeries series = new SplineSeries(); DataTemplate template1 = MainGrid3.Resources["splinetemplate"] as DataTemplate; DataTemplate template3 = MainGrid3.Resources["labelTemplate"] as DataTemplate; DataTemplate template4 = MainGrid3.Resources["headerTemplate"] as DataTemplate; DataTemplate template5 = MainGrid3.Resources["postfixTemplateSpline"] as DataTemplate; Style axisstyle = MainGrid3.Resources["axisLineStyle"] as Style; Style ticklinestyle = MainGrid3.Resources["minorTickLineStyle"] as Style; DateTimeAxis axis1 = new DateTimeAxis() { PlotOffset = 20, Interval = 1, IntervalType = DateTimeIntervalType.Months, LabelFormat = "MMM", Header = "Year 2014", LabelTemplate = template3, ShowGridLines = false, AxisLineStyle = axisstyle, MajorTickLineStyle = ticklinestyle, HeaderTemplate = template4 }; NumericalAxis axis2 = new NumericalAxis() { Minimum = -10, Maximum = 30, Interval = 5, Header = "Temperature(in Celsius)", HeaderTemplate = template4, LabelTemplate = template3, AxisLineStyle = axisstyle, MajorTickLineStyle = ticklinestyle }; series.XBindingPath = "Month"; series.YBindingPath = "Value2"; series.YAxis = axis2; series.XAxis = axis1; series.ItemsSource = viewModelSpline; series.CustomTemplate = template1; Basic_Chart5.Series.Clear(); Basic_Chart5.Series.Add(series); } else if (comboBox.SelectedIndex == 1 && viewModelBar != null) { (Basic_Chart5.Legend as ChartLegend).Visibility = Visibility.Collapsed; Basic_Chart51.Visibility = Visibility.Collapsed; Basic_Chart5.SetValue(Grid.RowSpanProperty, 2); Basic_Chart5.Axes.Clear(); Basic_Chart51.Axes.Clear(); Basic_Chart51.Series.Clear(); Basic_Chart5.Height = 515; Basic_Chart5.Header = new TextBlock() { Text = "Car Speed Comparison", Margin = new Thickness(50, 10, 0, 10), FontSize = 20, FontWeight = FontWeights.SemiBold }; Basic_Chart5.AreaBorderThickness = new Thickness(0, 0, 0, 0); BarSeries series1 = new BarSeries(); DataTemplate template3 = MainGrid3.Resources["labelTemplate"] as DataTemplate; DataTemplate template7 = MainGrid3.Resources["labelTemplate1"] as DataTemplate; DataTemplate template4 = MainGrid3.Resources["headerTemplate"] as DataTemplate; DataTemplate template1 = MainGrid3.Resources["newBarTemplate"] as DataTemplate; Style template5 = MainGrid3.Resources["axisLineStyle"] as Style; Style template6 = MainGrid3.Resources["minorTickLineStyle"] as Style; CategoryAxis axis1 = new CategoryAxis() { LabelTemplate = template3, AxisLineStyle = template5, MajorTickLineStyle = template6, ShowGridLines = false }; NumericalAxis axis2 = new NumericalAxis() { Header = "Acceleration rate", EdgeLabelsDrawingMode = EdgeLabelsDrawingMode.Shift, LabelTemplate = template7, AxisLineStyle = template5, MajorTickLineStyle = template6, HeaderTemplate = template4, Minimum = "0", Maximum = "300", Interval = "75", ShowGridLines = false }; series1.XBindingPath = "Month"; series1.YBindingPath = "Value1"; series1.CustomTemplate = template1; series1.SegmentSpacing = 0.9; series1.ItemsSource = viewModelBar; series1.XAxis = axis1; series1.YAxis = axis2; Basic_Chart5.Series.Clear(); Basic_Chart5.Series.Add(series1); } }
private void OnChartTypeSelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; if (Basic_Chart5 == null) { return; } if (comboBox.SelectedIndex == 0 && viewModelBar != null) { Basic_Chart5.SetValue(Grid.RowSpanProperty, 2); Basic_Chart5.Axes.Clear(); Basic_Chart5.Height = 515; Basic_Chart5.Header = "Car Speed Comparison"; Basic_Chart5.AreaBorderThickness = new Thickness(0, 0, 0, 0); BarSeries series1 = new BarSeries(); DataTemplate template1 = MainGrid3.Resources["newBarTemplate"] as DataTemplate; CategoryAxis axis1 = new CategoryAxis() { ShowGridLines = false }; NumericalAxis axis2 = new NumericalAxis() { Header = "Acceleration rate", EdgeLabelsDrawingMode = EdgeLabelsDrawingMode.Shift, LabelFormat = "0Kmph", Minimum = "0", Maximum = "300", Interval = "75", ShowGridLines = false }; series1.XBindingPath = "Month"; series1.YBindingPath = "Value1"; series1.CustomTemplate = template1; series1.SegmentSpacing = 0.9; series1.ItemsSource = viewModelBar; series1.XAxis = axis1; series1.YAxis = axis2; Basic_Chart5.Series.Clear(); Basic_Chart5.Series.Add(series1); } else if (comboBox.SelectedIndex == 1 && viewModelScatter != null) { Basic_Chart5.SetValue(Grid.RowSpanProperty, 2); Basic_Chart5.Axes.Clear(); Basic_Chart5.Header = "Global Stock Trend Comparison (2013 - 2014)"; Basic_Chart5.AreaBorderThickness = new Thickness(0, 0.5, 0.5, 0); Basic_Chart5.Height = 515; Basic_Chart5.AreaBorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD1, 0xD3, 0xD4)); DataTemplate template1 = MainGrid3.Resources["scattertemplate"] as DataTemplate; DataTemplate template2 = MainGrid3.Resources["scatterAdornmentTemplate"] as DataTemplate; ChartAdornmentInfo adornmentInfo1 = new ChartAdornmentInfo(); DateTimeAxis axis1 = new DateTimeAxis() { PlotOffset = 30, Interval = 1, IntervalType = DateTimeIntervalType.Months, LabelFormat = "MMM", Header = "Year 2014", ShowGridLines = false }; NumericalAxis axis2 = new NumericalAxis() { Minimum = 10, Maximum = 80, Interval = 10, Header = "Stock Price", LabelFormat = "$0", }; ScatterSeries series = new ScatterSeries(); adornmentInfo1.ShowLabel = true; adornmentInfo1.SegmentLabelContent = LabelContent.LabelContentPath; adornmentInfo1.LabelTemplate = template2; series.XBindingPath = "Year"; series.YBindingPath = "Count"; series.CustomTemplate = template1; series.YAxis = axis2; series.XAxis = axis1; series.ItemsSource = viewModelScatter; series.ScatterWidth = 64; series.ScatterHeight = 64; series.AdornmentsInfo = adornmentInfo1; Basic_Chart5.Series.Clear(); Basic_Chart5.Series.Add(series); } else if (comboBox.SelectedIndex == 2 && viewModelSpline != null) { Basic_Chart5.SetValue(Grid.RowSpanProperty, 2); Basic_Chart5.Axes.Clear(); Basic_Chart5.Height = 515; Basic_Chart5.Header = "Climate Graph"; Basic_Chart5.AreaBorderThickness = new Thickness(1, 1, 1, 1); Basic_Chart5.AreaBorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD1, 0xD3, 0xD4)); Basic_Chart5.AreaBorderThickness = new Thickness(0, 0.5, 0.5, 0); SplineSeries series = new SplineSeries(); DataTemplate template1 = MainGrid3.Resources["splinetemplate"] as DataTemplate; DateTimeAxis axis1 = new DateTimeAxis() { PlotOffset = 20, Interval = 1, IntervalType = DateTimeIntervalType.Months, LabelFormat = "MMM", Header = "Year 2014", ShowGridLines = false, }; NumericalAxis axis2 = new NumericalAxis() { Minimum = -10, Maximum = 30, Interval = 5, Header = "Temperature(in Celsius)", }; ChartStripLine stripline = new ChartStripLine() { Start = -0.2, Width = 0.2, Background = new SolidColorBrush(Colors.Red) }; axis2.StripLines.Add(stripline); series.XBindingPath = "Month"; series.YBindingPath = "Value2"; series.YAxis = axis2; series.XAxis = axis1; series.ItemsSource = viewModelSpline; series.CustomTemplate = template1; Basic_Chart5.Series.Clear(); Basic_Chart5.Series.Add(series); } }