This example shows how to create a Side-by-Side Bar chart at runtime.
In this example, you add Series
objects to the ChartControl.Series
collection and then populate the Series.Points
collection with points for each series.
The Chart Control uses the XY-Diagram to display bar series. Cast the ChartControl.Diagram
property to the XYDiagram
type to access diagram settings. The Chart Control determines the diagram type based on the series that is added first. We recommend that you access the diagram to configure its settings after at least one series is added to the chart.
Note that you can cast the series' View
property to the SideBySideBarSeriesView
type to access bar series appearance settings.
Files to Look At
Documentation
More Examples
- How to programmatically bind series to data and display them in separate panes
- How to create an Overlapped Range Bar chart
- How to create a Side-by-Side Full-Stacked Bar chart
- How to create a Side-by-Side Range Bar chart
- How to implement a custom bar animation
- How to create a Stacked Bar chart
- How to Create a Side-by-Side Stacked Bar Chart
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
namespace SideBySideBar2D {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
// Create an empty chart.
ChartControl sideBySideBarChart = new ChartControl();
// Create the first side-by-side bar series and add points to it.
Series series1 = new Series("Side-by-Side Bar Series 1", ViewType.Bar);
series1.Points.Add(new SeriesPoint("A", 10));
series1.Points.Add(new SeriesPoint("B", 12));
series1.Points.Add(new SeriesPoint("C", 14));
series1.Points.Add(new SeriesPoint("D", 17));
// Create the second side-by-side bar series and add points to it.
Series series2 = new Series("Side-by-Side Bar Series 2", ViewType.Bar);
series2.Points.Add(new SeriesPoint("A", 15));
series2.Points.Add(new SeriesPoint("B", 18));
series2.Points.Add(new SeriesPoint("C", 25));
series2.Points.Add(new SeriesPoint("D", 33));
// Add the series to the chart.
sideBySideBarChart.Series.Add(series1);
sideBySideBarChart.Series.Add(series2);
// Hide the legend (if necessary).
sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
// Rotate the diagram (if necessary).
((XYDiagram)sideBySideBarChart.Diagram).Rotated = true;
// Add a title to the chart (if necessary).
ChartTitle chartTitle1 = new ChartTitle();
chartTitle1.Text = "Side-by-Side Bar Chart";
sideBySideBarChart.Titles.Add(chartTitle1);
// Add the chart to the form.
sideBySideBarChart.Dock = DockStyle.Fill;
this.Controls.Add(sideBySideBarChart);
}
}
}