Create a simple chart in WinForm application

Applies to: Nevron Chart for .NET

How to create a simple chart in WinForm application from scratch in Visual Studio?

The following getting started guide will help you create a WinForm application, which displays the following chart:


Create a new WinForm application:
  1. Open Microsoft Visual Studio for .NET
  2. Select the File - New - Project command - the new project dialog will be displayed
  3. Select Visual C# Projects - Windows Applications
    Note: VS 2010 users must switch the target framework to ".NET Framework 4" as by default Windows Forms applications target ".NET Framework 4 Client Profile". This is required, because Nevron Chart for WinForms uses design time support features that are not present in ".NET Framework 4 Client Profile". To do this right click on the project in Solution Explorer and select properties. On the Application tab go to "Target Framework" and select ".NET Framework 4".
  4. Click the OK button - the designer for Form1 should automatically appear

Insert Nevron Chart control:

  1. The Nevron .NET Vision installation must register the NChartControl control in the Nevron Chart WinForm toolbox group. In case this group is created go to step 6.
  2. Right click on the Toolbox background. Select the "Choose Items…" command.
  3. In the "Customize Toolbox Items" dialog select the ".NET Framework Components" tab.
  4. Click on the "Browse..." button and select the Nevron.Chart.WinForm.dll assembly located in the Nevron .NET Vision installation directory.
  5. The NChartControl should appear at the end of the toolbox Windows Forms list.
  6. Drag and drop the NChartControl to the form and resize it as you see fit (or set its Dock property to Fill).
  7. Open the solution explorer and make sure to add references to the following Nevron assemblies: Nevron.Chart.dll; Nevron.Chart.WinForm.dll; Nevron.Presentation.dll; and Nevron.System.dll;
  8. Double click on Form1 to generate the Form1_Load method.
  9. Use the following code example to programmatically create the chart:

 

[C#]
using System;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.Chart.WinForm;
using Nevron.GraphicsCore;
...
private void Form1_Load(object sender, EventArgs e)
{
    nChartControl1.Controller.Tools.Add(new NSelectorTool());
    nChartControl1.Controller.Tools.Add(new NTrackballTool());
    nChartControl1.Settings.JitterMode = JitterMode.Auto;
    nChartControl1.Settings.JitteringSteps = 16;
  
    NPieChart chart = new NPieChart();
    nChartControl1.Charts.Clear();
    nChartControl1.Charts.Add(chart);
    chart.Dock = DockStyle.Fill;
    chart.DockMargins = new NMarginsL(5, 5, 5, 5);
    chart.Enable3D = true;
    chart.Width = 70;
    chart.Depth = 10;
    chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveElevated);
    chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyCameraLight);
  
    NPieSeries pie = (NPieSeries)chart.Series.Add(SeriesType.Pie);
    pie.PieStyle = PieStyle.SmoothEdgeRing;
    pie.InnerRadius = new NLength(40);
    pie.PieEdgePercent = 15; 
    pie.LabelMode = PieLabelMode.SpiderNoOverlap;
  
    pie.AddDataPoint(new NDataPoint(12, "Cars"));
    pie.AddDataPoint(new NDataPoint(42, "Trains"));
    pie.AddDataPoint(new NDataPoint(56, "Airplanes"));
    pie.AddDataPoint(new NDataPoint(23, "Buses"));
    pie.AddDataPoint(new NDataPoint(32, "Bikes"));
    pie.AddDataPoint(new NDataPoint(29, "Boats"));
  
    NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.BrightMultiColor);
    styleSheet.Apply(nChartControl1.Document);
  
    nChartControl1.Refresh(); 
}

[VB.NET]
Imports System
Imports System.Windows.Forms
Imports Nevron.Chart
Imports Nevron.Chart.WinForm
Imports Nevron.GraphicsCore
...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    NChartControl1.Controller.Tools.Add(New NSelectorTool())
    NChartControl1.Controller.Tools.Add(New NTrackballTool())
    NChartControl1.Settings.JitterMode = JitterMode.Auto
    NChartControl1.Settings.JitteringSteps = 16
  
    Dim chart As New NPieChart()
    NChartControl1.Charts.Clear()
    NChartControl1.Charts.Add(chart)
    chart.Dock = DockStyle.Fill
    chart.DockMargins = New NMarginsL(5, 5, 5, 5)
    chart.Enable3D = True
    chart.Width = 70
    chart.Depth = 10
    chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveElevated)
    chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyCameraLight)
  
    Dim pie As NPieSeries = DirectCast(chart.Series.Add(SeriesType.Pie), NPieSeries)
    pie.PieStyle = PieStyle.SmoothEdgeRing
    pie.InnerRadius = New NLength(40)
    pie.PieEdgePercent = 15
    pie.LabelMode = PieLabelMode.SpiderNoOverlap
  
    pie.AddDataPoint(New NDataPoint(12, "Cars"))
    pie.AddDataPoint(New NDataPoint(42, "Trains"))
    pie.AddDataPoint(New NDataPoint(56, "Airplanes"))
    pie.AddDataPoint(New NDataPoint(23, "Buses"))
    pie.AddDataPoint(New NDataPoint(32, "Bikes"))
    pie.AddDataPoint(New NDataPoint(29, "Boats"))
  
    Dim styleSheet As NStyleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.BrightMultiColor)
    styleSheet.Apply(NChartControl1.Document)
  
    NChartControl1.Refresh()
End Sub

Article ID: 112, Created On: 11/4/2010, Modified: 12/1/2010