corelibraries-devexpress-dot-xtracharts-dot-barseriesview-505a1202.md
Specifies the width of bars in Bar series, as a fraction of axis units.
Namespace : DevExpress.XtraCharts
Assembly : DevExpress.XtraCharts.v25.2.dll
NuGet Package : DevExpress.Charts
[XtraChartsLocalizableCategory(XtraChartsCategory.Layout)]
public double BarWidth { get; set; }
<XtraChartsLocalizableCategory(XtraChartsCategory.Layout)>
Public Property BarWidth As Double
| Type | Description |
|---|---|
| Double |
A Double value that specifies the bar’s width in fractions of axis units , where an axis unit is the distance between two major values on the axis. This value should be greater than 0.
|
The BarWidth property specifies the bar width for all Bar series, as a fraction of an axis measurement unit (the value that the NumericScaleOptions.MeasureUnit or DateTimeScaleOptions.MeasureUnit property specifies). This means that the distance is auto-adjusted when the chart is resized.
For 3D Bar series, the width of bars is specified via the Bar3DSeriesView.BarWidth property.
This example demonstrates how to create a histogram chart with a given number of bins.
private void Form1_Load(object sender, EventArgs e) {
// Load data to a chart.
chartControl1.DataSource = LoadDataTableFromXml("..\\..\\Data\\CityWeather.xml", "CityWeather");
Series series = new Series();
series.ArgumentDataMember = "Temperature";
SideBySideBarSeriesView view = series.View as SideBySideBarSeriesView;
view.Border.Visibility = DevExpress.Utils.DefaultBoolean.True;
view.BarWidth = 1;
chartControl1.Series.Add(series);
// Configure histogram options.
XYDiagram diagram = chartControl1.Diagram as XYDiagram;
NumericScaleOptions scaleOptions = diagram.AxisX.NumericScaleOptions;
scaleOptions.AggregateFunction = AggregateFunction.Histogram;
scaleOptions.ScaleMode = ScaleMode.Interval;
scaleOptions.IntervalOptions.DivisionMode = IntervalDivisionMode.Count;
scaleOptions.IntervalOptions.Count = 5;
scaleOptions.IntervalOptions.GridLayoutMode = GridLayoutMode.GridAndLabelShifted;
diagram.AxisX.Label.TextPattern = "{A:F0}°C";
diagram.AxisX.GridLines.Visible = true;
}
static DataTable LoadDataTableFromXml(string fileName, string tableName) {
DataSet xmlDataSet = new DataSet();
xmlDataSet.ReadXml(fileName);
return xmlDataSet.Tables[tableName];
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Load data to a chart.
chartControl1.DataSource = LoadDataTableFromXml("..\..\Data\CityWeather.xml", "CityWeather")
Dim series As Series = New Series()
series.ArgumentDataMember = "Temperature"
Dim view As SideBySideBarSeriesView = TryCast(series.View, SideBySideBarSeriesView)
view.Border.Visibility = DevExpress.Utils.DefaultBoolean.[True]
view.BarWidth = 1
chartControl1.Series.Add(series)
' Configure histogram options.
Dim diagram As XYDiagram = TryCast(chartControl1.Diagram, XYDiagram)
Dim scaleOptions As NumericScaleOptions = diagram.AxisX.NumericScaleOptions
scaleOptions.AggregateFunction = AggregateFunction.Histogram
scaleOptions.ScaleMode = ScaleMode.Interval
scaleOptions.IntervalOptions.DivisionMode = IntervalDivisionMode.Count
scaleOptions.IntervalOptions.Count = 5
scaleOptions.IntervalOptions.GridLayoutMode = GridLayoutMode.GridAndLabelShifted
diagram.AxisX.Label.TextPattern = "{A:F0}°C"
diagram.AxisX.GridLines.Visible = True
End Sub
Private Shared Function LoadDataTableFromXml(ByVal fileName As String, ByVal tableName As String) As DataTable
Dim xmlDataSet As DataSet = New DataSet()
xmlDataSet.ReadXml(fileName)
Return xmlDataSet.Tables(tableName)
End Function
The following API members configure the histogram options:
| Member | Description |
|---|---|
| ScaleGridOptionsBase.AggregateFunction | Gets or sets the value indicating the aggregate function that should be used to relieve data. |
| ScaleOptionsBase.ScaleMode | Gets or sets the scale mode for an axis. |
| NumericScaleOptions.IntervalOptions | Stores options for numeric axis when its ScaleMode is Interval. |
| NumericIntervalOptions.DivisionMode | Specifies how to divide axis scale into intervals. |
| NumericIntervalOptions.Count | Gets or sets the number of intervals when DivisionMode is Count. |
| NumericIntervalOptions.GridLayoutMode | Gets or sets the value that specifies the alignment of grid lines, major tickmarks and axis labels. |
The following code snippets (auto-collected from DevExpress Examples) contain references to the BarWidth property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-charts-create-stacked-bar-chart/CS/Series_StackedBarChart/Form1.cs#L31
StackedBarSeriesView view = (StackedBarSeriesView)chart.SeriesTemplate.View;
view.BarWidth = 0.8;
winforms-charts-create-a-side-by-side-stacked-bars/CS/SideBySideStackedBarChart/Form1.cs#L31
chart.SeriesTemplate.View = view;
view.BarWidth = 0.6;
winforms-charts-create-stacked-bar-chart/VB/Series_StackedBarChart/Form1.vb#L31
Dim view As StackedBarSeriesView = CType(chart.SeriesTemplate.View, StackedBarSeriesView)
view.BarWidth = 0.8
' Disable minor tickmarks on the x-axis:
winforms-charts-create-a-side-by-side-stacked-bars/VB/SideBySideStackedBarChart/Form1.vb#L33
chart.SeriesTemplate.View = view
view.BarWidth = 0.6
'Enable point labels and format their text.
See Also