Stacked Bar Charts with csASPNetGraph

csASPNetGraph can display data as stacked or grouped bar charts. These share most of the settings with ordinary bar charts although a different method is used to add the data values. AddGroupedData is used to add each data item. There can be several data items for each bar. As with the standard bar charts there are two possible orientations, controlled by the GraphType property. When GraphType is 4 the bars are vertical, when 5 the bars are horizontal.

The value of each data item can optionally be shown by setting ShowStackedValue to true. The font, colour and size of this text can be controlled and there is some choice as to the location of this text.

The first example shows 4 items and 2 groups. Here is the code that draws this graph:

Dim Graph As New GraphClass
Graph.AddGroupedData("Group1", "Item1", 17, "ff0000")
Graph.AddGroupedData("Group1", "Item2", 28, "00ff00")
Graph.AddGroupedData("Group2", "Item1", 7, "ff0000")
Graph.AddGroupedData("Group2", "Item2", 18, "00ff00")
Graph.GraphType = 4
Graph.GraphToBrowser(1)

The second example contains one extra line:

Graph.ShowStackedValue = true

This shows the values of each data item. These values could be placed outside the bars to left or right or rotated to read up the page. There is no check to make sure the label fits in the space so they are not suitable where small data values will be used.

The final example shows the chart with horizontal bars by setting GraphType to 5. The axis lengths have also been changed from the default to make them a better fit.

Graph.GraphType = 5
Graph.MaxX = 200
Graph.MaxY = 250

These examples have been kept simple to show just 2 bars with 2 data items in each. More detailed charts can be produced.

The trial component has a sample script included which contains all the properties and their default values. This can be useful when getting started with the component.

There are also examples available of Standard Bar Charts, Pie Charts and Line Graphs.

Download csASPNetGraph here.