Trackball Tool Example for WinForms

Nevron NOV Chart for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms Chart examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Trackball Tool Example for WinForms Description

This example demonstrates how to use the trackball tool to modify the chart rotation and elevation interactively using the mouse. You can also use Ctrl plus one of the arrow keys to change the chart elevation and rotation.


Trackball Tool Example

C# Trackball Tool Example Code for Nevron Chart for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Chart.Tools;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NTrackballToolExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

		#region Example

		public NWidget CreateExampleContent()
		{
            NChartViewWithCommandBars chartViewWithCommandBars = new NChartViewWithCommandBars();
            NChartView chartView = chartViewWithCommandBars.View;
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

            // configure title
            chartView.Surface.Titles[0].Text = "Trackball Tool";

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

            m_Chart.Enable3D = true;
            m_Chart.ModelWidth = 60;
            m_Chart.ModelHeight = 25;
            m_Chart.ModelDepth = 45;
            m_Chart.FitMode = ENCartesianChartFitMode.Aspect;
            m_Chart.Interactor = new NInteractor(new NTrackballTool());

            // apply predefined projection and lighting
            m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.BrightCameraLight);
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.Standard);

            // add axis labels
            NOrdinalScale ordinalScale = m_Chart.Axes[ENCartesianAxis.Depth].Scale as NOrdinalScale;
            ordinalScale.DisplayDataPointsBetweenTicks = true;
            ordinalScale = m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale as NOrdinalScale;
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);

            // add interlace stripe to the Y axis
            NLinearScale linearScale = m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
            NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            stripStyle.Interlaced = true;
            stripStyle.SetShowAtWall(ENChartWall.Back, true);
            stripStyle.SetShowAtWall(ENChartWall.Left, true);
            linearScale.Strips.Add(stripStyle);

            // add the first bar
            NBarSeries bar1 = new NBarSeries();
            m_Chart.Series.Add(bar1);
            bar1.MultiBarMode = ENMultiBarMode.Series;
            bar1.Name = "Bar1";
            bar1.Stroke = new NStroke(1, NColor.FromRGB(210, 210, 255));

            // add the second bar
            NBarSeries bar2 = new NBarSeries();
            m_Chart.Series.Add(bar2);
            bar2.MultiBarMode = ENMultiBarMode.Series;
            bar2.Name = "Bar2";
            bar2.Stroke = new NStroke(1, NColor.FromRGB(210, 255, 210));

            // add the third bar
            NBarSeries bar3 = new NBarSeries();
            m_Chart.Series.Add(bar3);
            bar3.MultiBarMode = ENMultiBarMode.Series;
            bar3.Name = "Bar3";
            bar3.Stroke = new NStroke(1, NColor.FromRGB(255, 255, 210));

            // add the fourth bar
            NBarSeries bar4 = new NBarSeries();
            m_Chart.Series.Add(bar4);
            bar4.MultiBarMode = ENMultiBarMode.Series;
            bar4.Name = "Bar4";
            bar4.Stroke = new NStroke(1, NColor.FromRGB(255, 210, 210));

            // add dummy data
            Random random = new Random();
            for (int i = 0; i < 6; i++)
            {
                bar1.DataPoints.Add(new NBarDataPoint(random.Next(100)));
                bar2.DataPoints.Add(new NBarDataPoint(random.Next(100)));
                bar3.DataPoints.Add(new NBarDataPoint(random.Next(100)));
                bar4.DataPoints.Add(new NBarDataPoint(random.Next(100)));
            }

            chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));

            m_Chart.Interactor = new NInteractor(new NTrackballTool());

			return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);

            NComboBox modelFitModeComboBox = new NComboBox();
            modelFitModeComboBox.Items.FillFromEnum();
            modelFitModeComboBox.SelectedIndex = (int)ENProjectionModelFitMode.Box;
            modelFitModeComboBox.SelectedIndexChanged += OnModelFitModeComboBoxSelectedIndexChanged;
            stack.Add(NPairBox.Create("Model Fit Mode:", modelFitModeComboBox));

            return group;
		}

        private void OnModelFitModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
        {
            m_Chart.Projection.ModelFitMode = (ENProjectionModelFitMode)arg.NewValue;
        }

        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to use the trackball tool to modify the chart rotation and elevation interactively using the mouse. You can also use Ctrl plus one of the arrow keys to change the chart elevation and rotation.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Hit Testing", "https://www.nevron.com/docs/openvision/chart-interactivity-hit-testing.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NTrackballTool m_TrackballTool; NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Trackball Tool Example for WinForms Solution

VB.NET Trackball Tool Example Code for Nevron Chart for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Chart.Tools
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System

Public Class Form1

#Region "Constructors"

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Set form title
        Text = "NOV WinForms - NTrackballToolExample"

        ' Create the NOV example and its controls
        Dim exampleContent As NWidget = CreateExampleContent()
        Dim exampleControls As NWidget = CreateExampleControls()
        If Not exampleControls Is Nothing Then
            exampleControls.PreferredWidth = 300
        End If

        ' Place the example and its controls in a pair box
        Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
        pairBox.FillMode = ENStackFillMode.First
        pairBox.FitMode = ENStackFitMode.First
        pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

        ' Host the example in the form
        Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
        host.Dock = DockStyle.Fill
        Controls.Add(host)
    End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            Dim chartViewWithCommandBars As NChartViewWithCommandBars = New NChartViewWithCommandBars()
            Dim chartView = chartViewWithCommandBars.View
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            ' configure title
            chartView.Surface.Titles(0).Text = "Trackball Tool"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)

            m_Chart.Enable3D = True
            m_Chart.ModelWidth = 60
            m_Chart.ModelHeight = 25
            m_Chart.ModelDepth = 45
            m_Chart.FitMode = ENCartesianChartFitMode.Aspect
            m_Chart.Interactor = New NInteractor(New NTrackballTool())

            ' apply predefined projection and lighting
            m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.BrightCameraLight)
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.Standard)

            ' add axis labels
            Dim ordinalScale As NOrdinalScale = TryCast(m_Chart.Axes(ENCartesianAxis.Depth).Scale, NOrdinalScale)
            ordinalScale.DisplayDataPointsBetweenTicks = True
            ordinalScale = TryCast(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale)
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)

            ' add interlace stripe to the Y axis
            Dim linearScale As NLinearScale = TryCast(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True
            stripStyle.SetShowAtWall(ENChartWall.Back, True)
            stripStyle.SetShowAtWall(ENChartWall.Left, True)
            linearScale.Strips.Add(stripStyle)

            ' add the first bar
            Dim bar1 As NBarSeries = New NBarSeries()
            m_Chart.Series.Add(bar1)
            bar1.MultiBarMode = ENMultiBarMode.Series
            bar1.Name = "Bar1"
            bar1.Stroke = New NStroke(1, NColor.FromRGB(210, 210, 255))

            ' add the second bar
            Dim bar2 As NBarSeries = New NBarSeries()
            m_Chart.Series.Add(bar2)
            bar2.MultiBarMode = ENMultiBarMode.Series
            bar2.Name = "Bar2"
            bar2.Stroke = New NStroke(1, NColor.FromRGB(210, 255, 210))

            ' add the third bar
            Dim bar3 As NBarSeries = New NBarSeries()
            m_Chart.Series.Add(bar3)
            bar3.MultiBarMode = ENMultiBarMode.Series
            bar3.Name = "Bar3"
            bar3.Stroke = New NStroke(1, NColor.FromRGB(255, 255, 210))

            ' add the fourth bar
            Dim bar4 As NBarSeries = New NBarSeries()
            m_Chart.Series.Add(bar4)
            bar4.MultiBarMode = ENMultiBarMode.Series
            bar4.Name = "Bar4"
            bar4.Stroke = New NStroke(1, NColor.FromRGB(255, 210, 210))

            ' add dummy data
            Dim random As Random = New Random()
            For i = 0 To 5
                bar1.DataPoints.Add(New NBarDataPoint(random.Next(100)))
                bar2.DataPoints.Add(New NBarDataPoint(random.Next(100)))
                bar3.DataPoints.Add(New NBarDataPoint(random.Next(100)))
                bar4.DataPoints.Add(New NBarDataPoint(random.Next(100)))
            Next

            chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series))

            m_Chart.Interactor = New NInteractor(New NTrackballTool())

            Return chartViewWithCommandBars
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

            Dim modelFitModeComboBox As NComboBox = New NComboBox()
            modelFitModeComboBox.Items.FillFromEnum(Of ENProjectionModelFitMode)()
            modelFitModeComboBox.SelectedIndex = CInt(ENProjectionModelFitMode.Box)
            modelFitModeComboBox.SelectedIndexChanged += AddressOf OnModelFitModeComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Model Fit Mode:", modelFitModeComboBox))

            Return group
        End Function

        Private Sub OnModelFitModeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
            m_Chart.Projection.ModelFitMode = CType(arg.NewValue, ENProjectionModelFitMode)
        End Sub

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to use the trackball tool to modify the chart rotation and elevation interactively using the mouse. You can also use Ctrl plus one of the arrow keys to change the chart elevation and rotation.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Hit Testing", "https://www.nevron.com/docs/openvision/chart-interactivity-hit-testing.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_TrackballTool As NTrackballTool Private m_Chart As NCartesianChart #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Trackball Tool Example for WinForms Solution

Related Documentation Links