[]
Bar charts are used to compare categorical data through horizontal bars. The length of each bar represents the value of the corresponding category. The data displayed in columns or rows of a worksheet can be plotted in a bar chart. In these charts, the categories are organized along the vertical axis, where the data values are displayed along the horizontal axis.
Spread Windows Forms supports the following types of bar charts.
Sample Image | Description |
|---|---|
| ChartType.BarClustered
Represents a clustered bar chart. It is used to display the comparisons of values across different categories. |
| ChartType.BarStacked
Represents a stacked bar chart. It is used to display the relationship of each item/category to the whole in two-dimensional and three-dimensional rectangles. |
| ChartType.BarStacked100
Represents a 100% stacked bar chart. It is used to display the comparisons of the percentage that each of the values contributes to the total across different categories. |
Refer to the following example code to add a bar chart.
C#
// Enable enhanced shape and chart engines.
fpSpread1.Features.EnhancedShapeEngine = true;
fpSpread1.Features.EnhancedChartEngine = true;
// Add data.
fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 1].Value = "Q1";
fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 2].Value = "Q2";
fpSpread1.AsWorkbook().ActiveSheet.Cells[0, 3].Value = "Q3";
fpSpread1.AsWorkbook().ActiveSheet.Cells[1, 0].Value = "Mobile Phones";
fpSpread1.AsWorkbook().ActiveSheet.Cells[2, 0].Value = "Laptops";
fpSpread1.AsWorkbook().ActiveSheet.Cells[3, 0].Value = "Tablets";
Random random = new Random();
for (var r = 1; r <= 3; r++)
{
for (var c = 1; c <= 3; c++)
{
fpSpread1.AsWorkbook().ActiveSheet.Cells[r, c].Value = random.Next(0, 100);
}
}
fpSpread1.AsWorkbook().ActiveSheet.Cells["A1:D4"].Select();
// Add BarClustered chart.
fpSpread1.AsWorkbook().ActiveSheet.Shapes.AddChart(GrapeCity.Spreadsheet.Charts.ChartType.BarClustered, 100, 150, 400, 300, true);VB
' Enable enhanced shape and chart engines.
fpSpread1.Features.EnhancedShapeEngine = True
fpSpread1.Features.EnhancedChartEngine = True
' Add data.
fpSpread1.AsWorkbook().ActiveSheet.Cells(0, 1).Value = "Q1"
fpSpread1.AsWorkbook().ActiveSheet.Cells(0, 2).Value = "Q2"
fpSpread1.AsWorkbook().ActiveSheet.Cells(0, 3).Value = "Q3"
fpSpread1.AsWorkbook().ActiveSheet.Cells(1, 0).Value = "Mobile Phones"
fpSpread1.AsWorkbook().ActiveSheet.Cells(2, 0).Value = "Laptops"
fpSpread1.AsWorkbook().ActiveSheet.Cells(3, 0).Value = "Tablets"
Dim random As New Random()
For r As Integer = 1 To 3
For c As Integer = 1 To 3
fpSpread1.AsWorkbook().ActiveSheet.Cells(r, c).Value = random.Next(0, 100)
Next
Next
fpSpread1.AsWorkbook().ActiveSheet.Cells("A1:D4").Select()
' Add BarClustered chart.
fpSpread1.AsWorkbook().ActiveSheet.Shapes.AddChart(GrapeCity.Spreadsheet.Charts.ChartType.BarClustered, 100, 150, 400, 300, True)