Hi Marcus,
The following code shows how to create a layout where the legends always use uniform scaling and push the charts to the left if the space assigned to them is not sufficient. Also the charts are aligned on their left and right sides:
private NChart CreateChart()
{
NChart chart = new NCartesianChart();
chart.BoundsMode = BoundsMode.Stretch;
NLineSeries line = new NLineSeries();
Random rand = new Random();
int range = rand.Next(200);
for (int i = 0; i < 10; i++)
{
line.Values.Add(rand.Next(range));
}
line.Legend.Mode = SeriesLegendMode.DataPoints;
chart.Series.Add(line);
return chart;
}
private NLegend CreateLegend()
{
NLegend legend = new NLegend();
legend.Data.ExpandMode = LegendExpandMode.VertWrap;
legend.FitAlignment = ContentAlignment.TopRight;
return legend;
}
private NDockPanel CreatePanel()
{
// create a dock panel with legend and chart
NDockPanel panel = new NDockPanel();
panel.PositionChildPanelsInContentBounds = true;
panel.Margins = new NMarginsL(10);
NLegend legend = CreateLegend();
legend.Dock = DockStyle.Right;
legend.Margins = new NMarginsL(10, 0, 0, 0);
panel.ChildPanels.Add(legend);
NChart chart = CreateChart();
chart.Dock = DockStyle.Fill;
panel.ChildPanels.Add(chart);
chart.DisplayOnLegend = legend;
return panel;
}
private void Form1_Load(object sender, EventArgs e)
{
nChartControl1.Panels.Clear();
// create some panels that contain a chart and legend
int count = 4;
int panelPercent = 100 / count;
for (int i = 0; i < 4; i++)
{
NDockPanel panel1 = CreatePanel();
panel1.Dock = DockStyle.Top;
panel1.Size = new NSizeL(new NLength(0), new NLength(panelPercent, NRelativeUnit.ParentPercentage));
nChartControl1.Panels.Add(panel1);
}
// align the charts
NSideGuideline guidelineRight = new NSideGuideline(PanelSide.Right);
NSideGuideline guidelineLeft = new NSideGuideline(PanelSide.Left);
for (int i = 0; i < nChartControl1.Charts.Count; i++)
{
NChart chart = nChartControl1.Charts[i];
guidelineRight.Targets.Add(chart);
guidelineLeft.Targets.Add(chart);
}
nChartControl1.Document.RootPanel.Guidelines.Add(guidelineRight);
nChartControl1.Document.RootPanel.Guidelines.Add(guidelineLeft);
}
Let us know if you meet any problems.
Best Regards,
Nevron Support Team