(By implementing these addresses, at best, a subset of this rather old question, since this is only one type of diagram ...)
Just fwiw, creating a histogram in the Grid , as Ed suggests , is pretty simple. Here is a quick and dirty version:
Add a Grid to your Window XAML. Just for testing, here, which completely fills Window .
<Grid> <Grid Name="myGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="auto" Height="auto" Margin="10,10,10,10" /> </Grid>
Now insert these two utility functions somewhere in your project. They provide simple, single-color columns and uneven but centered label text for the x axis.
I think the only nasty kludge is maxHeight in calling _placeSingleColorColumn .
Worth mentioning: I have no shortcuts for the y axis in this quick and dirty version.
private void _placeSingleColorColumn(Grid grid, Color color, int height, int colNum, int maxHeight) { Brush brush = new SolidColorBrush(color); Rectangle rect = new Rectangle(); rect.Fill = brush; Grid.SetColumn(rect, colNum); Grid.SetRow(rect, maxHeight - height); Grid.SetRowSpan(rect, height); grid.Children.Add(rect); } private void _createLabels(Grid grid, string[] labels) { RowDefinition rowDefnLabels = new RowDefinition(); grid.RowDefinitions.Add(rowDefnLabels); for (int i = 0; i < labels.Length; i++) { TextBlock block = new TextBlock(); block.Text = labels[i]; block.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; Grid.SetColumn(block, i); Grid.SetRow(block, grid.RowDefinitions.Count); grid.Children.Add(block); } }
It really is. Here's some insanely fast and dirty code example for creating a 10 by 10 grid with some data examples.
public void createGrid10x10() { Random random = new Random(); for (int i=0; i<10; i++) { ColumnDefinition colDef = new ColumnDefinition(); myGrid.ColumnDefinitions.Add(colDef); RowDefinition rowDef = new RowDefinition(); myGrid.RowDefinitions.Add(rowDef); Color color = i % 2 == 0 ? Colors.Red : Colors.Blue; _placeSingleColorColumn(this.myGrid, color, random.Next(1,11), i, 10); } string[] aLabels = "Dogs,Cats,Birds,Snakes,Rabbits,Hamsters,Horses,Rats,Bats,Unicorns".Split(','); _createLabels(this.myGrid, aLabels); }
Add one line to your MainWindow constructor, and you're done, afaict.
public MainWindow() { InitializeComponent(); this.createGrid10x10(); }
Now you have a histogram that will resize and remain proportional as the window resizes, etc.


Adding more labels (bar values above, Y axis labels, etc.) should be pretty simple, if you understand above. Just enter another column and / or row, create TextBlock s and put them in the right places.