Scale 3D to Content Area 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.

Scale 3D to Content Area Example for WinForms Description

The example demonstrates how to convert from scale to content area coordinates as well as how to perform custom painting.


Scale 3DTo Content Area Example

C# Scale 3D to Content Area 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 - NScale3DToContentAreaExample";

			// 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 = "Converting from Scale 3D to Content Area";

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

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

            m_Chart.Enable3D = true;

            // setup X axis
            NLinearScale scaleX = new NLinearScale();
			scaleX.MajorGridLines = new NScaleGridLines();
			scaleX.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
			m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;

			// setup Y axis
			NLinearScale scaleY = new NLinearScale();
			scaleY.MajorGridLines = new NScaleGridLines();
			scaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;

            // add interlaced stripe for Y axis
            NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            strip.Interlaced = true;
            scaleY.Strips.Add(strip);

            m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale = scaleY;

			// add a point series
			m_Point = new NPointSeries();
			m_Point.Name = "Point Series";
			m_Point.DataLabelStyle = new NDataLabelStyle(false);
			m_Point.Fill = new NColorFill(NColor.DarkOrange);
			m_Point.Size = 5;
			m_Point.Shape = ENPointShape3D.Bar;
			m_Point.UseXValues = true;
			m_Point.UseZValues = true;
			m_Chart.Series.Add(m_Point);

			// add some sample data
			NDataPointCollection dataPoints = m_Point.DataPoints;

			Random random = new Random();

			for (int i = 0; i < 100; i++)
			{
				double u1 = random.NextDouble();
				double u2 = random.NextDouble();

				if (u1 == 0)
					u1 += 0.0001;

				if (u2 == 0)
					u2 += 0.0001;

				double z0 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2);
				double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2);

				dataPoints.Add(new NPointDataPoint(z0, z1));
			}

			m_Chart.Enabled = true;
            m_Chart.PostPaint += OnChartPostPaint;

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

			return chartViewWithCommandBars;
		}



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

            m_DataPointIndexNumericUpDown = new NNumericUpDown();
			m_DataPointIndexNumericUpDown.Minimum = 0;
            m_DataPointIndexNumericUpDown.Maximum = m_Point.DataPoints.Count - 1;
            m_DataPointIndexNumericUpDown.ValueChanged += OnDataPointIndexNumericUpDownValueChanged;
            stack.Add(NPairBox.Create("Data Point Index:", m_DataPointIndexNumericUpDown));

            return group;
		}
		/// 
		/// 
		/// 
		/// 
        public string GetExampleDescription()
		{
            return @"

The example demonstrates how to convert from scale to content area coordinates as well as how to perform custom painting.

"; } /// /// 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"), ("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html"), }; } #endregion #region Implementation /// /// Gets the data point position in content area coordinates /// /// /// private NPoint GetDataPointPosition(int index) { if (index < 0) { index = 0; } if (index >= m_Point.DataPoints.Count) { index = m_Point.DataPoints.Count - 1; } double x = m_Point.DataPoints[index].X; double y = m_Point.DataPoints[index].Y; double z = m_Point.DataPoints[index].Z; return m_Chart.TransformLogicalToView3D(new NPoint3D(x, y, z), ENCartesianAxis.PrimaryX, ENCartesianAxis.PrimaryY, ENCartesianAxis.Depth); } /// /// Gets the cross path /// /// /// private static NGraphicsPath GetCustomPaintShapePath(NPoint point) { NRectangle rect = new NRectangle(point.X, point.Y, 0, 0); rect.Inflate(15, 15); NGraphicsPath path = new NGraphicsPath(); double fX13 = rect.X + (1.0f / 3.0f) * rect.Width; double fX23 = rect.X + (2.0f / 3.0f) * rect.Width; double fY13 = rect.Y + (1.0f / 3.0f) * rect.Height; double fY23 = rect.Y + (2.0f / 3.0f) * rect.Height; NPoint[] points = new NPoint[12]; points[0] = new NPoint(fX13, rect.Y); points[1] = new NPoint(fX23, rect.Y); points[2] = new NPoint(fX23, fY13); points[3] = new NPoint(rect.Right, fY13); points[4] = new NPoint(rect.Right, fY23); points[5] = new NPoint(fX23, fY23); points[6] = new NPoint(fX23, rect.Bottom); points[7] = new NPoint(fX13, rect.Bottom); points[8] = new NPoint(fX13, fY23); points[9] = new NPoint(rect.X, fY23); points[10] = new NPoint(rect.X, fY13); points[11] = new NPoint(fX13, fY13); path.AddPolygon(points); return path; } #endregion #region Event Handlers /// /// Callled after the chart is painted /// /// private void OnChartPostPaint(NPaintEventArgs arg) { int count = m_Point.DataPoints.Count; NPoint mousePosition; if (!NMouse.TryGetLocalPosition(m_Chart, out mousePosition)) return; arg.PaintVisitor.ClearStyles(); arg.PaintVisitor.SetFill(new NColorFill(NColor.Green)); // get the data point position in scale coordinates NPoint dataPointPosition = GetDataPointPosition((int)m_DataPointIndexNumericUpDown.Value); NGraphicsPath path = GetCustomPaintShapePath(dataPointPosition); arg.PaintVisitor.PaintPath(path); } /// /// /// /// private void OnDataPointIndexNumericUpDownValueChanged(NValueChangeEventArgs arg) { // force repaint m_Chart.InvalidateDisplay(); } #endregion #region Fields NPointSeries m_Point; NCartesianChart m_Chart; NNumericUpDown m_DataPointIndexNumericUpDown; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Scale 3D to Content Area Example for WinForms Solution

VB.NET Scale 3D to Content Area 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 - NScale3DToContentAreaExample"

        ' 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 = "Converting from Scale 3D to Content Area"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)

            Dim interactor As NInteractor = New NInteractor()
            interactor.Add(New NTrackballTool())
            m_Chart.Interactor = interactor

            m_Chart.Enable3D = True

            ' setup X axis
            Dim scaleX As NLinearScale = New NLinearScale()
            scaleX.MajorGridLines = New NScaleGridLines()
            scaleX.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot
            m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale = scaleX

            ' setup Y axis
            Dim scaleY As NLinearScale = New NLinearScale()
            scaleY.MajorGridLines = New NScaleGridLines()
            scaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot

            ' add interlaced stripe for Y axis
            Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            strip.Interlaced = True
            scaleY.Strips.Add(strip)

            m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale = scaleY

            ' add a point series
            m_Point = New NPointSeries()
            m_Point.Name = "Point Series"
            m_Point.DataLabelStyle = New NDataLabelStyle(False)
            m_Point.Fill = New NColorFill(NColor.DarkOrange)
            m_Point.Size = 5
            m_Point.Shape = ENPointShape3D.Bar
            m_Point.UseXValues = True
            m_Point.UseZValues = True
            m_Chart.Series.Add(m_Point)

            ' add some sample data
            Dim dataPoints = m_Point.DataPoints

            Dim random As Random = New Random()

            For i = 0 To 99
                Dim u1 As Double = random.NextDouble()
                Dim u2 As Double = random.NextDouble()

                If u1 = 0 Then u1 += 0.0001

                If u2 = 0 Then u2 += 0.0001

                Dim z0 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2)
                Dim z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2)

                dataPoints.Add(New NPointDataPoint(z0, z1))
            Next

            m_Chart.Enabled = True
            Me.m_Chart.PostPaint += AddressOf OnChartPostPaint

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

            Return chartViewWithCommandBars
        End Function



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

            m_DataPointIndexNumericUpDown = New NNumericUpDown()
            m_DataPointIndexNumericUpDown.Minimum = 0
            m_DataPointIndexNumericUpDown.Maximum = m_Point.DataPoints.Count - 1
            Me.m_DataPointIndexNumericUpDown.ValueChanged += AddressOf OnDataPointIndexNumericUpDownValueChanged
            stack.Add(NPairBox.Create("Data Point Index:", m_DataPointIndexNumericUpDown))

            Return group
        End Function
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function GetExampleDescription() As String
            Return "

The example demonstrates how to convert from scale to content area coordinates as well as how to perform custom painting.

" 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"), ("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html")} End Function #End Region #Region "Implementation" ''' ''' Gets the data point position in content area coordinates ''' ''' ''' Private Function GetDataPointPosition(index As Integer) As NPoint If index < 0 Then index = 0 End If If index >= m_Point.DataPoints.Count Then index = m_Point.DataPoints.Count - 1 End If Dim x = m_Point.DataPoints(index).X Dim y = m_Point.DataPoints(index).Y Dim z = m_Point.DataPoints(index).Z Return m_Chart.TransformLogicalToView3D(New NPoint3D(x, y, z), ENCartesianAxis.PrimaryX, ENCartesianAxis.PrimaryY, ENCartesianAxis.Depth) End Function ''' ''' Gets the cross path ''' ''' ''' Private Shared Function GetCustomPaintShapePath(point As NPoint) As NGraphicsPath Dim rect As NRectangle = New NRectangle(point.X, point.Y, 0, 0) rect.Inflate(15, 15) Dim path As NGraphicsPath = New NGraphicsPath() Dim fX13 = rect.X + 1.0F / 3.0F * rect.Width Dim fX23 = rect.X + 2.0F / 3.0F * rect.Width Dim fY13 = rect.Y + 1.0F / 3.0F * rect.Height Dim fY23 = rect.Y + 2.0F / 3.0F * rect.Height Dim points = New NPoint(11) {} points(0) = New NPoint(fX13, rect.Y) points(1) = New NPoint(fX23, rect.Y) points(2) = New NPoint(fX23, fY13) points(3) = New NPoint(rect.Right, fY13) points(4) = New NPoint(rect.Right, fY23) points(5) = New NPoint(fX23, fY23) points(6) = New NPoint(fX23, rect.Bottom) points(7) = New NPoint(fX13, rect.Bottom) points(8) = New NPoint(fX13, fY23) points(9) = New NPoint(rect.X, fY23) points(10) = New NPoint(rect.X, fY13) points(11) = New NPoint(fX13, fY13) path.AddPolygon(points) Return path End Function #End Region #Region "Event Handlers" ''' ''' Callled after the chart is painted ''' ''' Private Sub OnChartPostPaint(arg As NPaintEventArgs) Dim count = m_Point.DataPoints.Count Dim mousePosition As NPoint If Not NMouse.TryGetLocalPosition(m_Chart, mousePosition) Then Return arg.PaintVisitor.ClearStyles() arg.PaintVisitor.SetFill(New NColorFill(NColor.Green)) ' get the data point position in scale coordinates Dim dataPointPosition = GetDataPointPosition(m_DataPointIndexNumericUpDown.Value) Dim path = GetCustomPaintShapePath(dataPointPosition) arg.PaintVisitor.PaintPath(path) End Sub ''' ''' ''' ''' Private Sub OnDataPointIndexNumericUpDownValueChanged(arg As NValueChangeEventArgs) ' force repaint m_Chart.InvalidateDisplay() End Sub #End Region #Region "Fields" Private m_Point As NPointSeries Private m_Chart As NCartesianChart Private m_DataPointIndexNumericUpDown As NNumericUpDown #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) Scale 3D to Content Area Example for WinForms Solution

Related Documentation Links