In This Topic
A Floating Bar Chart displays a sequence of horizontal or vertical bars, each bar representing a one-dimensional value range. A Floating Bar chart can be used as a Gantt chart if the Y axis is in date-time scale mode. Gantt charts are popular in project management for planning the use of resources over time. Different activities that take place in the project are denoted by their start and finish dates/times.
The following images represent different floating bar chart variations.
Figure 1.
Creating a floating bar series
Floating Bar series are represented by the NFloatBarSeries type. An instance of this type must be added to the series collection of a Cartesian chart.
C# |
Copy Code
|
// obtain a reference to the Cartesian chart that is created by default
NCartesianChart chart = (NCartesianChart)chartControl.Charts[0];
// add a float bar series to it
NFloatBarSeries floatbar = (NFloatBarSeries)chart.Series.Add(SeriesType.FloatBar);
|
Visual Basic |
Copy Code
|
' obtain a reference to the Cartesian chart that is created by default
Dim chart As NCartesianChart = chartControl.Charts(0)
' add a float bar series to it
Dim floatbar As NFloatBarSeries = chart.Series.Add(SeriesType.FloatBar)
|
Passing Data
Once the floating bar series is created you can add some data in it. Floating Bar series use the Values data series for the bar begin values, the XValues data series for the X positions, the ZValues data series for Z positions.
In addition to these data series the floating bar series provides another data series of type Double, which holds the bar end values. It is accessible through the EndValues property of the NFloatBarSeries object. For consistency the Values data series can also be accesses through the BeginValues property of the NFloatBarSeries object.
You can either manipulate directly these data series, or use the data point interface to supply data to the floating bar series. The NFloatBarDataPoint class provides several constructors that can be very helpful when you add floating bar data points. Please refer to the Working with Data Points topic for more information.
Controlling the bars dimensions
The width and depth dimensions of the floating bars in a non-scatter floating bar series are specified in percents of the grid cell they occupy. The WidthPercent and DepthPercent properties control these percentage values. The following code will make the bars a little bit bolder then they are by default:
C# |
Copy Code
|
floatbar.WidthPercent = 80;
floatbar.DepthPercent = 70;
|
Visual Basic |
Copy Code
|
floatbar.WidthPercent = 80
floatbar.DepthPercent = 70
|
When the UseXValues property is set to true, the bar width is controlled through the BarWidth property. When the UseZValues property is set to true, the bar depth is controlled through the BarDepth property. Both BarWidth and BarDepth are of type NLength and can be defined in percents of the chart dimensions. The following code will set the bar width to five percent of the chart width and the bar depth to two percent of the chart depth.
C# |
Copy Code
|
floatbar.BarWidth = new NLength(5, NRelativeUnit.ParentPercentage);
floatbar.BarDepth = new NLength(2, NRelativeUnit.ParentPercentage);
|
Visual Basic |
Copy Code
|
floatbar.BarWidth = New NLength(5, NRelativeUnit.ParentPercentage)
floatbar.BarDepth = New NLength(2, NRelativeUnit.ParentPercentage)
|
Controlling the bar shape
The shape of the floating bars is controlled with the help of the BarShape property. It accepts values from the BarShape enumeration. For example the following code will display the bars as cones:
C# |
Copy Code
|
floatbar.BarShape = BarShape.Cone;
|
Visual Basic |
Copy Code
|
floatbar.BarShape = BarShape.Cone
|
When the bars are displayed as Smooth or Cut edge bar you can control whether top and bottom edges of the bar are displayed in the respective manner with the help of the HasTopEdge and HasBottomEdge properties. The following code will display the bar as smooth edge bar with top and bottom edges:
C# |
Copy Code
|
floatbar.BarShape = BarShape.SmoothEdgeBar;
floatbar.HasTopEdge = true;
floatbar.HasBottomEdge = true;
|
Visual Basic |
Copy Code
|
floatbar.BarShape = BarShape.SmoothEdgeBar
floatbar.HasTopEdge = True
floatbar.HasBottomEdge = True
|
The size of the edge is controlled in percents of the smaller width or depth bar dimension. By default it is set to 15. The following code will make the smooth bar edges twice bigger:
C# |
Copy Code
|
floatbar.BarEdgePercent = 30;
|
Visual Basic |
Copy Code
|
floatbar.BarEdgePercent = 30
|
Palette
The float bar series can have an associated palette, in which case the Fill properties of the series / data points are discarded. The following code snippet shows how to apply a palette filling:
C# |
Copy Code
|
NPalette palette = new NPalette();
palette.Clear();
palette.Add(0, Color.Green);
palette.Add(60, Color.Yellow);
palette.Add(120, Color.Red);
floatBarSeries.Palette = palette;
|
Visual Basic |
Copy Code
|
Dim palette As New NPalette palette.Clear()
palette.Add(0, Color.Green)
palette.Add(60, Color.Yellow)
palette.Add(120, Color.Red)
floatBarSeries.Palette = palette
|
Connector Lines and Gannt Connector Lines
The float bar series can display connector lines which link the begin/end of adjacent bars. The following code snippet shows how to enable connector lines and modify the connector lines stroke style:
C# |
Copy Code
|
floatBar.ShowConnectorLines = true;
floatBar.ConnectorLineStrokeStyle = new NStrokeStyle(1, Color.Red);
|
VB.NET |
Copy Code
|
floatBar.ShowConnectorLines = True floatBar.ConnectorLineStrokeStyle = New NStrokeStyle(1, Color.Red)
|
Gannt Connector lines connect the bars end value to one or more user specified bars begin value. This feature allows you to display Gantt charts. The following code shows how to create a simple Gantt chart:
C# |
Copy Code
|
NChart chart = nChartControl1.Charts[0];
NFloatBarSeries floatBar = new NFloatBarSeries();
chart.Series.Add(floatBar);
floatBar.BeginValues.Add(10);
floatBar.EndValues.Add(20);
floatBar.NextTasks.Add(0, new uint[] { 1, 2 });
floatBar.BeginValues.Add(20);
floatBar.EndValues.Add(30);
floatBar.BeginValues.Add(30);
floatBar.EndValues.Add(40);
floatBar.ShowGanttConnectorLines = true;
floatBar.GanttConnectorLineStrokeStyle = new NStrokeStyle(1, Color.Red);
|
Visual Basic |
Copy Code
|
Dim chart As NChart = NChartControl1.Charts(0)
Dim floatBar As New NFloatBarSeries
chart.Series.Add(floatBar)
floatBar.BeginValues.Add(10)
floatBar.EndValues.Add(20)
floatBar.NextTasks.Add(0, New UInt32() {1, 2})
floatBar.BeginValues.Add(20)
floatBar.EndValues.Add(30)
floatBar.BeginValues.Add(30)
floatBar.EndValues.Add(40)
floatBar.ShowGanttConnectorLines = True
floatBar.GanttConnectorLineStrokeStyle = New NStrokeStyle(1, Color.Red)
|
Note that the code tells the control to connect the first bar with the second and third ones - this is done by adding a uint array of data point indices for the NextTasks dictionary.
Formatting Commands
The NFloatBarSeries class extends the formatting commands set inherited from the NXYZScatterSeries class with the following formatting commands:
<begin> - the current data point begin value (obtained from the Values data series)
<end> - the current data point end value (obtained from the EndValues data series)
Related Examples
Windows forms: Chart Gallery\Float Bar\Standard Float Bar
See Also