Bar Chart Legend Position


https://www.nevron.com/Forum/Topic14358.aspx
Print Topic | Close Window

By Mike Holmes - 2 Years Ago
How can I, move the Bar Chart Legend Position to be away from the chart, also ideally I would like to remove the boxhttps://www.nevron.com/forum/uploads/images/bae595a8-ede6-45e7-9245-c82f.jpg
By Nevron Support - 2 Years Ago
Hi Mike,

We would recommend that you docking to achive this layout. In this case you can dock the lagend to the right,  the label to the top and finally dock the chart to fill the rest. That way the chart will automatically measure the sizes of the label and legend and they'll not overlap - for example:

   nChartControl1.Panels.Clear();

    NLabel label = new NLabel("Bar Chart");
    label.DockMode = PanelDockMode.Top;
    label.Margins = new Nevron.GraphicsCore.NMarginsL(10);
    nChartControl1.Panels.Add(label);

    NLegend legend = new NLegend();
    legend.DockMode = PanelDockMode.Right;
    legend.FitAlignment = ContentAlignment.TopCenter;
    legend.Margins = new Nevron.GraphicsCore.NMarginsL(10);
    legend.OuterTopBorderStyle.Width = new Nevron.GraphicsCore.NLength(0);
    legend.OuterLeftBorderStyle.Width = new Nevron.GraphicsCore.NLength(0);
    legend.OuterRightBorderStyle.Width = new Nevron.GraphicsCore.NLength(0);
    legend.OuterBottomBorderStyle.Width = new Nevron.GraphicsCore.NLength(0);
    nChartControl1.Panels.Add(legend);

    NCartesianChart chart = new NCartesianChart();
    chart.BoundsMode = Nevron.GraphicsCore.BoundsMode.Stretch;
    chart.Margins = new Nevron.GraphicsCore.NMarginsL(10);
    chart.DockMode = PanelDockMode.Fill;
    nChartControl1.Panels.Add(chart);
    chart.DisplayOnLegend = legend;

    NBarSeries bar = new NBarSeries();
    bar.Values.Add(10);
    bar.Values.Add(20);
    bar.Values.Add(30);
    bar.DataLabelStyle.Visible = true;
    chart.Series.Add(bar);

This code also shows how to turn off the border around the legend.

You can take a look at the following topic in the documentation:
http://helpdotnetvision.nevron.com/#UsersGuide_Layout_Docking_Panels.html

We hope this helps - let us know if you have any questions.