private void GenerateDataPoint(KeyValuePair<string, double> kvp, Range range)
{
// Add a column and add a grid in this column
_series.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
Grid point = new Grid();
Grid.SetColumn(point, _series.ColumnDefinitions.Count - 1);
_series.Children.Add(point);
// Divide the grid in 3 rows
double val = kvp.Value;
double negativeFraction = range.Fraction(Math.Min(val, 0));
double positiveFraction = 1 - range.Fraction(Math.Max(val, 0));
point.RowDefinitions.Add(new RowDefinition { Height = new GridLength(positiveFraction, GridUnitType.Star) });
point.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1 - positiveFraction - negativeFraction, GridUnitType.Star), MinHeight = MinBarSize});
point.RowDefinitions.Add(new RowDefinition { Height = new GridLength(negativeFraction, GridUnitType.Star) });
Border axisX = new Border
{
BorderThickness = new Thickness(0.75),
BorderBrush = ForegroundColor,
Opacity = 0.5,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = val > 0 ? VerticalAlignment.Bottom : VerticalAlignment.Top,
Margin = new Thickness(-5, 0, -5, 0)
};
Grid.SetRow(axisX, 1);
point.Children.Add(axisX);
// Put a bar in the middle row
Border bar = new Border
{
Margin = new Thickness(MarginBetweenBars, 0, MarginBetweenBars, 0),
Background = GetColorByIndex(0)
};
Grid.SetRow(bar, 1);
SetTooltip(bar, kvp.Key, FormattedValue(kvp.Value));
point.Children.Add(bar);
}