Profile Picture

Legend Formatting

Posted By Marcus McCallum 12 Years Ago
Author
Message
Marcus McCallum
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 6 Years Ago
Posts: 29, Visits: 61

Hi,

I am struggling to work out the best way to format some Legends. I have set-up the following:

1. 7 stacking charts and I have used NGuidleine to align them.

2. I would like the Legends for each chart to be side-by-side with the relevant chart.

3. The top chart will have an unknown number of items in the legend (in the attached picture it has 11). This is why I have set a fixed row size.

4. All other charts will have Legends with fixed numbers of items.

5. I have attached what I get with the following code

Legend.Location = New NPointL(Point.X, Point.Y)

Legend.Data.ExpandMode = LegendExpandMode.RowsFixed

Legend.Data.RowCount = 4

Legend.UseAutomaticSize = False

Legend.Size = New NSizeL(New NLength(18, NRelativeUnit.ParentPercentage), New NLength(10, NRelativeUnit.ParentPercentage))

Legend.BoundsMode = BoundsMode.Fit

Legend.ContentAlignment = ContentAlignment.BottomRight

I have tried to use a one-size fits all approach, but this doesn't look too good. I was just wondering if anyone had any better ways of presenting the Legends, as I am currently struggling with the BoundsMode, Legend Size etc. I would like them to look more consistent, with perhaps the same font size, but from what I can see the font size is determined by the size of the Legend box.

As I said, any help or advice appreciated on better ways of presenting my Legends.

Thanks,
Marcus



Attachments
Legend Formatting.bmp (57 views, 780.00 KB)
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 8:46 AM
Posts: 3,054, Visits: 4,012

Hi Marcus,

You can try using the vertical legend wrapping - in this mode the legend will automatically increase the number of columns when it's size exceeds the specified bounds - to specify this mode you must use:

legend.Data.ExpandMode = LegendExpandMode.VertWrap;

Also can you post the picture you refer to?

 



Best Regards,
Nevron Support Team



Marcus McCallum
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 6 Years Ago
Posts: 29, Visits: 61

I have now uploaded the picture I referred to in the original post.

Regards,

Marcus



Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 8:46 AM
Posts: 3,054, Visits: 4,012

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





Similar Topics


Reading This Topic