public void IncrementValue(object key, double v) { total += v; ChartValue cv = index[key]; cv.Value += v; this.dirty = true; }
public ChartColumn(ChartValue cv, NumberFormatInfo nfi, Color c1, double colWidth, double availableHeight, double range) { this.availableHeight = availableHeight; if (range == 0) { range = availableHeight; } this.range = range; vtext = new TextBlock(); Binding binding = new Binding(); binding.Source = this; binding.Path = new PropertyPath("ColumnValue"); binding.Converter = new NumberConverter(nfi); vtext.SetBinding(TextBlock.TextProperty, binding); vtext.HorizontalAlignment = HorizontalAlignment.Center; r = new Rectangle(); r.Width = colWidth; r.Height = 0; r.RadiusX = r.RadiusY = 2; HlsColor hls = new HlsColor(c1); hls.Lighten(.3f); Color c2 = hls.Color; hls = new HlsColor(c1); hls.Darken(.3f); Color stroke = hls.Color; r.Stroke = new SolidColorBrush(stroke); r.StrokeThickness = 1; r.Fill = new LinearGradientBrush(c1, c2, new Point(0, 0), new Point(0, 1)); TextBlock label = new TextBlock(); label.Text = cv.Label; label.HorizontalAlignment = HorizontalAlignment.Center; this.Children.Add(vtext); this.Children.Add(r); this.Children.Add(label); this.value = cv; this.SetValue(ColumnValueProperty, cv.Value); }
public void AddColumn(object key, string label, double value) { ChartValue cv = null; if (!index.ContainsKey(key)) { cv = new ChartValue(label, value, key); values.Add(cv); index[key] = cv; } else { cv = index[key]; cv.Value += value; } total += value; this.dirty = true; }
void UpdatePointer(Point pos) { if (data != null && data.AllSeries.Count > 0 && scale != null && scale.ScaleX > 0) { if (selectedSeries == null) { selectedSeries = data.AllSeries[data.AllSeries.Count - 1]; } Point legendPos = this.TransformToDescendant(legend).Transform(pos); Rect legendArea = new Rect(0, 0, legend.ActualWidth, legend.ActualHeight); bool insideLegend = (legendArea.Contains(legendPos)); if (pointer == null) { PathGeometry diamond = new PathGeometry(); PathFigure figure = new PathFigure(); diamond.Figures.Add(figure); figure.IsClosed = true; figure.IsFilled = true; figure.StartPoint = new Point(0, -5); figure.Segments.Add(new LineSegment(new Point(5, 0), true)); figure.Segments.Add(new LineSegment(new Point(0, 5), true)); figure.Segments.Add(new LineSegment(new Point(-5, 0), true)); pointer = new Path() { Data = diamond, Fill = Brushes.Red }; this.Children.Add(pointer); } if (tooltip == null) { tooltip = new Border(); tooltip.Padding = new Thickness(2); tooltip.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; tooltip.VerticalAlignment = System.Windows.VerticalAlignment.Top; tooltip.BorderBrush = Brushes.Black; tooltip.BorderThickness = new Thickness(1); tooltip.Background = Brushes.White; label = new TextBlock(); label.Foreground = Brushes.Black; tooltip.Child = label; this.Children.Add(tooltip); } ChartSeries series = selectedSeries; var values = series.Values; int i = (int)(pos.X / scale.ScaleX); if (i >= 0 && i < values.Count) { ChartValue v = values[i]; Selected = v; label.Text = v.Label; if (insideLegend) { tooltip.Visibility = System.Windows.Visibility.Hidden; } else { tooltip.UpdateLayout(); double tipPositionX = pos.X; if (tipPositionX + tooltip.ActualWidth > this.ActualWidth) { tipPositionX = this.ActualWidth - tooltip.ActualWidth; } double tipPositionY = pos.Y - label.ActualHeight - 4; if (tipPositionY < 0) { tipPositionY = 0; } tooltip.Margin = new Thickness(tipPositionX, tipPositionY, 0, 0); tooltip.Visibility = System.Windows.Visibility.Visible; } double value = v.Value; if (series.Flipped) { value = -value; } Point pointerPosition = transform.Transform(new Point(i, value)); pointer.RenderTransform = new TranslateTransform(pointerPosition.X, pointerPosition.Y); pointer.Visibility = System.Windows.Visibility.Visible; } else { tooltip.Visibility = System.Windows.Visibility.Hidden; pointer.Visibility = System.Windows.Visibility.Hidden; } } else { // todo } }