Nevron Open Vision Documentation
Chart / Legend / Overview
In This Topic
    Overview
    In This Topic

    NOV Chart for .NET has an integrated legend that can display various information about the chart. The flexible design of the integrated legend helps you to customize the displayed data and its appearance with ease.

    The legend is represented by the NLegend class. You can have an unlimited number of legends inside a chart view surface. By default the chart will create a single legend linked to a single chart if you use CreatePredefinedChart method of the NChartViewSurface object.

     Obtaining a Reference to Existing Legend

    When you create a predefined chart type (Cartesian, Polar, Pie etc) you can obtain a reference to the to the legend using the Legends property of the NChartViewSurface object:

    C#
    Copy Code

    NChartView chartView = new NChartView();

    chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

    NLegend legend = chartView.Surface.Legends[0];

    NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];

    The above code shows how to obtain a reference to the created default cartesian chart and its associated legend object.

     Creating a New Legend

    Some charts require multiple legends as well as different legend positions. In such cases you can populate the chart view surface with code. The following code snippet shows how to create a cartesian chart with a legend that is docked to the top right corner of its plot area:

    C#
    Copy Code

    NChartView chartView = new NChartView();

    // create a dock panel with label and chart
    NDockPanel dockPanel = new NDockPanel();
    chartView.Surface.Content = dockPanel;

    // crete a docked label
    NLabel label = new NLabel();
    label.Text =
    "Legend in Plot Area";
    label.Margins =
    new NMargins(10);
    NDockLayout.SetDockArea(label, ENDockArea.Top);
    dockPanel.AddChild(label);

    // create a new cartesian chart
    NCartesianChart chart = new NCartesianChart();
    NDockLayout.SetDockArea(chart, ENDockArea.Center);
    dockPanel.AddChild(chart);

    NLegend legend = new NLegend();
    legend.HorizontalPlacement =
    ENHorizontalPlacement.Right;
    legend.BackgroundFill =
    new NColorFill(NColor.FromColor(NColor.White, 0.5f));
    NDockLayout.SetDockArea(legend, ENDockArea.Top);

    chart.Content = legend;
    chart.SetPredefinedCartesianAxes(
    ENPredefinedCartesianAxis.XOrdinalYLinear);
    chart.Legend = legend;

    NBarSeries bar = new NBarSeries();
    bar.DataPoints.Add(
    new NBarDataPoint(10));
    bar.DataPoints.Add(
    new NBarDataPoint(18));
    bar.DataPoints.Add(
    new NBarDataPoint(25));
    chart.Series.Add(bar);

     

    See Also