Applies to: Nevron Chart for .NET
How to created Cluster Stacked Bar or Column Charts?
You can create a Cluster Stacked horizontal or vertical Bar Charts combination by using the Multi Bar Stacked and Clustered modes. You can create multiple Cluster Bars for the following Chart Types: Series, Stacked or Stack Percent (100% Stacked Bar).
[C#]
using
System.Drawing;
using
System.Windows.Forms;
using
Nevron;
using
Nevron.Chart;
using
Nevron.Chart.WinForm;
using
Nevron.GraphicsCore;
...
private
void
Form1_Load(
object
sender, EventArgs e)
{
nChartControl1.Controller.Tools.Add(
new
NSelectorTool());
nChartControl1.Controller.Tools.Add(
new
NTrackballTool());
nChartControl1.Settings.JitterMode = JitterMode.Enabled;
nChartControl1.Settings.JitteringSteps = 16;
// obtain a reference to the Cartesian chart that is created by default
NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
chart.Axis(StandardAxis.Depth).Visible =
false
;
chart.Dock = DockStyle.Fill;
chart.DockMargins =
new
NMarginsL(5, 5, 5, 5);
chart.Enable3D =
true
;
chart.Depth = 10;
chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective2);
chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.GlitterLeft);
// configure the legend
NLegend Legend = (NLegend)nChartControl1.Legends[0];
Legend.Data.ExpandMode = LegendExpandMode.RowsFixed;
Legend.Data.RowCount = 1;
Legend.Dock = DockStyle.Top;
Legend.DockMargins =
new
NMarginsL(5, 5, 5, 5);
Legend.BoundsMode = BoundsMode.None;
// add interlaced stripe to the Y axis
NScaleStripStyle stripStyle =
new
NScaleStripStyle(
new
NColorFillStyle(Color.Beige),
null
,
true
, 0, 0, 1, 1);
stripStyle.SetShowAtWall(ChartWallType.Back,
true
);
stripStyle.SetShowAtWall(ChartWallType.Left,
true
);
stripStyle.Interlaced =
true
;
((NStandardScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator).StripStyles.Add(stripStyle);
// first cluster
NBarSeries c1bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
c1bar1.Name =
"Series1"
;
c1bar1.BarShape = BarShape.Cylinder;
c1bar1.DataLabelStyle.Visible =
false
;
NBarSeries c1bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
c1bar2.Name =
"Series2"
;
c1bar2.BarShape = BarShape.Cylinder;
c1bar2.DataLabelStyle.Visible =
false
;
c1bar1.MultiBarMode = MultiBarMode.Series;
c1bar2.MultiBarMode = MultiBarMode.Stacked;
// stack on c1bar1
// second cluster
NBarSeries c2bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
c2bar1.Name =
"Series3"
;
c2bar1.BarShape = BarShape.Cylinder;
c2bar1.DataLabelStyle.Visible =
false
;
NBarSeries c2bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
c2bar2.Name =
"Series4"
;
c2bar2.BarShape = BarShape.Cylinder;
c2bar2.DataLabelStyle.Visible =
false
;
c2bar1.MultiBarMode = MultiBarMode.Clustered;
// display next to c1bar1
c2bar2.MultiBarMode = MultiBarMode.Stacked;
// stack on c2bar1
// fill with random data
Random rand =
new
Random();
c1bar1.Values.FillRandomRange(rand, 5, 10, 100);
c1bar2.Values.FillRandomRange(rand, 5, 10, 500);
c2bar1.Values.FillRandomRange(rand, 5, 10, 500);
c2bar2.Values.FillRandomRange(rand, 5, 10, 500);
NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Autumn);
styleSheet.Apply(nChartControl1.Document);
nChartControl1.Refresh();
}
[VB.NET]
Imports
System
Imports
System.Drawing
Imports
System.Windows.Forms
Imports
Nevron
Imports
Nevron.Chart
Imports
Nevron.Chart.WinForm
Imports
Nevron.GraphicsCore
...
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
nChartControl1.Controller.Tools.Add(
New
NSelectorTool())
nChartControl1.Controller.Tools.Add(
New
NTrackballTool())
nChartControl1.Settings.JitterMode = JitterMode.Enabled
nChartControl1.Settings.JitteringSteps = 16
' obtain a reference to the Cartesian chart that is created by default
Dim
chart
As
NCartesianChart =
DirectCast
(nChartControl1.Charts(0), NCartesianChart)
chart.Axis(StandardAxis.Depth).Visible =
False
chart.Dock = DockStyle.Fill
chart.DockMargins =
New
NMarginsL(5, 5, 5, 5)
chart.Enable3D =
True
chart.Depth = 10
chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective2)
chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.GlitterLeft)
' configure the legend
Dim
Legend
As
NLegend =
DirectCast
(nChartControl1.Legends(0), NLegend)
Legend.Data.ExpandMode = LegendExpandMode.RowsFixed
Legend.Data.RowCount = 1
Legend.Dock = DockStyle.Top
Legend.DockMargins =
New
NMarginsL(5, 5, 5, 5)
Legend.BoundsMode = BoundsMode.None
' add interlaced stripe to the Y axis
Dim
stripStyle
As
New
NScaleStripStyle(
New
NColorFillStyle(Color.Beige),
Nothing
,
True
, 0, 0, 1, 1)
stripStyle.SetShowAtWall(ChartWallType.Back,
True
)
stripStyle.SetShowAtWall(ChartWallType.Left,
True
)
stripStyle.Interlaced =
True
DirectCast
(chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator, NStandardScaleConfigurator).StripStyles.Add(stripStyle)
' first cluster
Dim
c1bar1
As
NBarSeries =
DirectCast
(chart.Series.Add(SeriesType.Bar), NBarSeries)
c1bar1.Name =
"Series1"
c1bar1.BarShape = BarShape.Cylinder
c1bar1.DataLabelStyle.Visible =
False
Dim
c1bar2
As
NBarSeries =
DirectCast
(chart.Series.Add(SeriesType.Bar), NBarSeries)
c1bar2.Name =
"Series2"
c1bar2.BarShape = BarShape.Cylinder
c1bar2.DataLabelStyle.Visible =
False
c1bar1.MultiBarMode = MultiBarMode.Series
c1bar2.MultiBarMode = MultiBarMode.Stacked
' stack on c1bar1
' second cluster
Dim
c2bar1
As
NBarSeries =
DirectCast
(chart.Series.Add(SeriesType.Bar), NBarSeries)
c2bar1.Name =
"Series3"
c2bar1.BarShape = BarShape.Cylinder
c2bar1.DataLabelStyle.Visible =
False
Dim
c2bar2
As
NBarSeries =
DirectCast
(chart.Series.Add(SeriesType.Bar), NBarSeries)
c2bar2.Name =
"Series4"
c2bar2.BarShape = BarShape.Cylinder
c2bar2.DataLabelStyle.Visible =
False
c2bar1.MultiBarMode = MultiBarMode.Clustered
' display next to c1bar1
c2bar2.MultiBarMode = MultiBarMode.Stacked
' stack on c2bar1
' fill with random data
Dim
rand
As
New
Random()
c1bar1.Values.FillRandomRange(rand, 5, 10, 100)
c1bar2.Values.FillRandomRange(rand, 5, 10, 500)
c2bar1.Values.FillRandomRange(rand, 5, 10, 500)
c2bar2.Values.FillRandomRange(rand, 5, 10, 500)
Dim
styleSheet
As
NStyleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Autumn)
styleSheet.Apply(nChartControl1.Document)
nChartControl1.Refresh()
End
Sub
Article ID: 135, Created On: 11/22/2010, Modified: 12/1/2010