Add NOV Chart control in WinForms at runtime

Add NOV Chart control in WinForms at runtime



To get started and host NOV in your WinForms application, take a look at: Getting Started with NOV in WinForms using only code

The following topic shows how to add a NOV Chart Widget (control) in WinForms at runtime.

1. Reference the NOV Assemblies
Ensure that your application references the following NOV dlls:
Nevron.Nov.Presentation.dll - core NOV portable assembly;
Nevron.Nov.Host.WinBase.dll - base assembly for Windows presentation hosts (WinForm and WPF);
Nevron.Nov.Host.WinForm.dll - presentation host for Window Forms;
Nevron.Nov.Chart.dll - assembly for the NChartModule;

These assemblies are located in NOV installation folder: C:\Program Files (x86)\Nevron Software\Nevron Open Vision VERSION\Bin\Win

2. When initializing the NOV Application, make sure to create the Chart module
Open the Program.cs file and use the following code:

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
 
            // Apply license for redistribution here. You can skip this code when evaluating NOV.
            NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
            // Install NOV
            NModule[] modules = new NModule[] {
                // TODO: Create modules here
                NChartModule.Instance
            };
            NNovApplicationInstaller.Install(modules);
            Application.Run(new Form1());
        }
    }
}

3. Create the Chart View and setup a Bar series
Open the Form1.cs file and use the following code to create the Chart:

using Nevron.Nov.Chart;
using Nevron.Nov.Graphics;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            // clear all controls from the form
            Controls.Clear();
 
            // create chart
            NChartView chartView = new NChartView();
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);
 
            // configure chart title
            chartView.Surface.Titles[0].Text = "Standard Bar";
 
            // configure chart
            NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
 
            chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
 
            // add interlace stripe
            NLinearScale linearScale = chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
            NScaleStrip strip = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1);
            strip.Interlaced = true;
            linearScale.Strips.Add(strip);
 
            // setup a bar series
            NBarSeries bar = new NBarSeries();
            bar.Name = "Bar Series";
            bar.InflateMargins = true;
            bar.UseXValues = false;
 
            bar.Shadow = new NShadow(NColor.LightGray, 2, 2);
 
            // add some data to the bar series
            bar.LegendView.Mode = ENSeriesLegendMode.DataPoints;
            bar.DataPoints.Add(new NBarDataPoint(18, "C++"));
            bar.DataPoints.Add(new NBarDataPoint(15, "Ruby"));
            bar.DataPoints.Add(new NBarDataPoint(21, "Python"));
            bar.DataPoints.Add(new NBarDataPoint(23, "Java"));
            bar.DataPoints.Add(new NBarDataPoint(27, "Javascript"));
            bar.DataPoints.Add(new NBarDataPoint(29, "C#"));
            bar.DataPoints.Add(new NBarDataPoint(26, "PHP"));
 
            chart.Series.Add(bar);
 
            // create NOV host
            NNovWidgetHost<NChartView> host = new NNovWidgetHost<NChartView>(chartView);
            host.Dock = DockStyle.Fill;
            Controls.Add(host);
        }
    }
}

Run the application - it should display a simple form with a Bar Chart series.




Using Visual Basic .NET (VB.NET)
When you create a Visual Basic Windows Forms Application, reference the NOV Assemblies and use the following code in your Form1.vb:

Imports Nevron.Nov
Imports Nevron.Nov.Windows.Forms
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Graphics
 
Public Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
        ' clear all controls from the form
        Controls.Clear()
 
        ' TODO: Apply license for redistribution here. You can skip this code when evaluating NOV.
        NLicenseManager.Instance.SetLicense(New NLicense("LICENSE KEY"))
 
        ' Install Nevron Open Vision modules
        Dim modules() As NModule = {NChartModule.Instance}
        NNovApplicationInstaller.Install(modules)
 
        ' create chart
        Dim chartView As New NChartView()
        chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)
 
        ' configure chart title
        chartView.Surface.Titles(0).Text = "Standard Bar"
 
        ' configure chart
        Dim chart As NCartesianChart = DirectCast(chartView.Surface.Charts(0), NCartesianChart)
 
        chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
 
        ' add interlace stripe
        Dim linearScale As NLinearScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
        Dim strip As New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1)
        strip.Interlaced = True
        linearScale.Strips.Add(strip)
 
        ' setup a bar series
        Dim bar As New NBarSeries()
        bar.Name = "Bar Series"
        bar.InflateMargins = True
        bar.UseXValues = False
 
        bar.Shadow = New NShadow(NColor.LightGray, 2, 2)
 
        ' add some data to the bar series
        bar.LegendView.Mode = ENSeriesLegendMode.DataPoints
        bar.DataPoints.Add(New NBarDataPoint(18, "C++"))
        bar.DataPoints.Add(New NBarDataPoint(15, "Ruby"))
        bar.DataPoints.Add(New NBarDataPoint(21, "Python"))
        bar.DataPoints.Add(New NBarDataPoint(23, "Java"))
        bar.DataPoints.Add(New NBarDataPoint(27, "Javascript"))
        bar.DataPoints.Add(New NBarDataPoint(29, "C#"))
        bar.DataPoints.Add(New NBarDataPoint(26, "PHP"))
 
        chart.Series.Add(bar)
 
        ' Create the host widget
        Dim host As New NNovWidgetHost(Of NChartView)(chartView)
        host.Dock = DockStyle.Fill
 
        ' add the host in the form controls
        Controls.Add(host)
    End Sub
End Class


For more information about the NOV Chart component, take a look at the Help Documentation:
Chart > Chart Overview

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 244, Created On: 8/9/2016, Modified: 9/27/2016