Content Area Zoom and Pan Tools Example for Blazor

Content Area Zoom and Pan Tools Example for Blazor

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

Content Area Zoom and Pan Tools Example for Blazor Description

This example demonstrates how to use the NContentAreaZoomTool and NContentAreaPanTool to enable interactive zooming and panning of the chart's content area using the mouse.


Content Area Zoom and Pan Tools Example

C# Content Area Zoom and Pan Tools Example Code for Nevron Chart for Blazor
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 - NContentAreaZoomAndPanToolsExample";

			// 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 = "Content Area Zooming and Panning";

            // 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;

            // 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 = 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));

            NContentAreaPanTool contentAreaPanTool = new NContentAreaPanTool();
            contentAreaPanTool.StartMouseButtonEvent = ENMouseButtonEvent.RightButtonDown;
            contentAreaPanTool.EndMouseButtonEvent = ENMouseButtonEvent.RightButtonUp;

            m_Chart.Interactor = new NInteractor(new NTool[] { new NContentAreaZoomTool(), contentAreaPanTool });

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

            NButton resetZoomAndOffsetButton = new NButton("Reset Zoom and Offset");
            resetZoomAndOffsetButton.Click += OnResetZoomAndOffsetButtonClick;
            stack.Add(resetZoomAndOffsetButton);

            return group;
		}

        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to use the NContentAreaZoomTool and NContentAreaPanTool to enable interactive zooming and panning of the chart's content area using the mouse.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Zooming and Scrolling", "https://www.nevron.com/docs/openvision/chart-interactivity-zooming-and-scrolling.html"), ("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnResetZoomAndOffsetButtonClick(NEventArgs arg) { m_Chart.ContentAreaOffset = new NPoint(); m_Chart.ContentAreaZoomFactor = new NRectangle(0, 0, 1, 1); } #endregion #region Fields NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Content Area Zoom and Pan Tools Example for Blazor Solution