Applies to: Nevron Chart for .NET
How to create a chart layout so that the chart doesn’t overlap with the legend?
For this purpose you can use panel docking. The following example shows how to achieve one of the “classic” chart layouts – label on top, legend on the right and chart filling the rest:
[C#]
using
System;
using
System.Drawing;
using
System.Windows.Forms;
using
Nevron.Chart;
using
Nevron.GraphicsCore;
...
private
void
Form1_Load(
object
sender, EventArgs e)
{
nChartControl1.Panels.Clear();
nChartControl1.Settings.JitterMode = JitterMode.Enabled;
nChartControl1.Settings.JitteringSteps = 4;
NLabel label =
new
NLabel(
"Chart Title"
);
// label docked on the top
label.Dock = DockStyle.Top;
label.Margins =
new
NMarginsL(20, 10, 20, 20);
nChartControl1.Panels.Add(label);
NLegend legend =
new
NLegend();
// legend docks on the left
legend.Dock = DockStyle.Right;
legend.FitAlignment = ContentAlignment.TopCenter;
legend.Margins =
new
NMarginsL(10, 0, 10, 10);
nChartControl1.Panels.Add(legend);
NCartesianChart chart =
new
NCartesianChart();
chart.Margins =
new
NMarginsL(10, 0, 0, 10);
// configure the chart to occupies the whole area
chart.Dock = DockStyle.Fill;
chart.BoundsMode = BoundsMode.Stretch;
chart.Enable3D =
true
;
chart.Axis(StandardAxis.Depth).Visible =
false
;
chart.Fit3DAxisContent =
true
;
chart.Depth = 10;
chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective2);
chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.GlitterLeft);
nChartControl1.Panels.Add(chart);
chart.DisplayOnLegend = legend;
// add chart series
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.Clustered;
// fill with random data
Random rand =
new
Random();
c1bar1.Values.FillRandomRange(rand, 5, 10, 100);
c1bar2.Values.FillRandomRange(rand, 5, 10, 500);
// apply predefined style sheet
NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Autumn);
styleSheet.Apply(nChartControl1.Document);
nChartControl1.Refresh();
}
[VB.NET]
Imports
Microsoft.VisualBasic
Imports
System
Imports
System.Drawing
Imports
System.Windows.Forms
Imports
Nevron.Chart
Imports
Nevron.GraphicsCore
...
Private
Sub
Form1_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
MyBase
.Load
nChartControl1.Panels.Clear()
nChartControl1.Settings.JitterMode = JitterMode.Enabled
nChartControl1.Settings.JitteringSteps = 4
Dim
label
As
NLabel =
New
NLabel(
"Chart Title"
)
' label docked on the top
label.Dock = DockStyle.Top
label.Margins =
New
NMarginsL(20, 10, 20, 20)
nChartControl1.Panels.Add(label)
Dim
legend
As
NLegend =
New
NLegend()
' legend docks on the left
legend.Dock = DockStyle.Right
legend.FitAlignment = ContentAlignment.TopCenter
legend.Margins =
New
NMarginsL(10, 0, 10, 10)
nChartControl1.Panels.Add(legend)
Dim
chart
As
NCartesianChart =
New
NCartesianChart()
chart.Margins =
New
NMarginsL(10, 0, 0, 10)
' configure the chart to occupies the whole area
chart.Dock = DockStyle.Fill
chart.BoundsMode = BoundsMode.Stretch
chart.Enable3D =
True
chart.Axis(StandardAxis.Depth).Visible =
False
chart.Fit3DAxisContent =
True
chart.Depth = 10
chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective2)
chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.GlitterLeft)
nChartControl1.Panels.Add(chart)
chart.DisplayOnLegend = legend
' add chart series
Dim
c1bar1
As
NBarSeries =
CType
(chart.Series.Add(SeriesType.Bar), NBarSeries)
c1bar1.Name =
"Series1"
c1bar1.BarShape = BarShape.Cylinder
c1bar1.DataLabelStyle.Visible =
False
Dim
c1bar2
As
NBarSeries =
CType
(chart.Series.Add(SeriesType.Bar), NBarSeries)
c1bar2.Name =
"Series2"
c1bar2.BarShape = BarShape.Cylinder
c1bar2.DataLabelStyle.Visible =
False
c1bar1.MultiBarMode = MultiBarMode.Series
c1bar2.MultiBarMode = MultiBarMode.Clustered
' fill with random data
Dim
rand
As
Random =
New
Random()
c1bar1.Values.FillRandomRange(rand, 5, 10, 100)
c1bar2.Values.FillRandomRange(rand, 5, 10, 500)
' apply predefined style sheet
Dim
styleSheet
As
NStyleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Autumn)
styleSheet.Apply(nChartControl1.Document)
nChartControl1.Refresh()
End
Sub
Take a look at the following examples:
All Examples >> Layout
All Examples >> Panels >> Legend Docking
You can also check out the topics related to chart layout in the User’s Guide >> Layout:
http://helpdotnetvision.nevron.com/Article ID: 208, Created On: 3/2/2012, Modified: 3/6/2012