private void OnPieSliceClicked(object sender, ChartDataValue e) { if (e.UserData is CategoryData data) { Selection = data; } }
private UIElement OnGenerateTip(ChartDataValue value) { var tip = new StackPanel() { Orientation = Orientation.Vertical }; tip.Children.Add(new TextBlock() { Text = value.Label, FontWeight = FontWeights.Bold }); tip.Children.Add(new TextBlock() { Text = value.Value.ToString("C0") }); return(tip); }
private void AddRow(int index, ChartDataValue dv) { Row ui = null; if (LegendGrid.RowDefinitions.Count <= index) { LegendGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); } if (this.elements.Count > index) { // reuse previous elements! ui = this.elements[index]; } else { ui = new Row(); if (dv.Color.HasValue) { var c = dv.Color.Value; ToggleButton colorSwatch = new ToggleButton(); colorSwatch.Template = swatchTemplate; colorSwatch.Margin = new Thickness(2); colorSwatch.Width = 16; colorSwatch.Height = 16; colorSwatch.DataContext = dv; ui.button = colorSwatch; } TextBlock label = new TextBlock() { Text = dv.Label, Margin = new Thickness(5, 2, 5, 2) }; ui.label = label; TextBlock total = new TextBlock() { Text = dv.Value.ToString("C0"), Margin = new Thickness(5, 2, 5, 2), HorizontalAlignment = HorizontalAlignment.Right }; ui.value = total; this.elements.Add(ui); } ui.item = dv; if (ui.button != null) { var c = dv.Color.Value; HlsColor hls = new HlsColor(c); ui.button.Background = new SolidColorBrush(c); if (hls.Luminance < 0.5) { ui.button.Foreground = Brushes.White; } else { ui.button.Foreground = Brushes.Black; } ui.button.DataContext = dv; Grid.SetRow(ui.button, index); Grid.SetColumn(ui.button, 0); LegendGrid.Children.Add(ui.button); ui.button.Checked -= OnColorSwatchToggled; ui.button.Unchecked -= OnColorSwatchToggled; ui.button.IsChecked = dv.Hidden; ui.button.Checked += OnColorSwatchToggled; ui.button.Unchecked += OnColorSwatchToggled; } ui.label.Text = dv.Label; Grid.SetRow(ui.label, index); Grid.SetColumn(ui.label, 1); LegendGrid.Children.Add(ui.label); ui.value.Text = dv.Value.ToString("C0"); Grid.SetRow(ui.value, index); Grid.SetColumn(ui.value, 2); LegendGrid.Children.Add(ui.value); }
private void OnLegendToggled(object sender, ChartDataValue e) { // filtering out a category. FilterChartData(); }
private void OnPieSliceHovered(object sender, ChartDataValue e) { }