Manhattan Bar Example for WPF

Nevron NOV Chart for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF 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.

Manhattan Bar Example for WPF Description

This example demonstrates a Manhattan bar chart. This type of chart is created with several bar series displayed with the MultiBarMode property set to Series.


Manhattan Bar Example

C# Manhattan Bar Example Code for Nevron Chart for WPF
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 - NManhattanBarExample";

			// 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 = "Manhattan Bar Chart";

            // 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.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(new string[] {    "Chicago",
                                                                                                    "Los Angeles",
                                                                                                    "Miami",
                                                                                                    "New York" });
            ordinalScale.DisplayDataPointsBetweenTicks = true;
            ordinalScale.Labels.Style.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0);

            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
            m_Bar1 = new NBarSeries();
            m_Chart.Series.Add(m_Bar1);
            m_Bar1.MultiBarMode = ENMultiBarMode.Series;
            m_Bar1.Name = "Bar1";
            m_Bar1.Stroke = new NStroke(1, NColor.FromRGB(210, 210, 255));

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

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

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

            OnPositiveDataButtonClick(null);

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

			{
				NComboBox barShapeComobo = new NComboBox();
				barShapeComobo.Items.FillFromEnum();
                barShapeComobo.SelectedIndexChanged += OnBarShapeComoboSelectedIndexChanged;
                barShapeComobo.SelectedIndex = (int)ENBarShape.Rectangle;
                stack.Add(NPairBox.Create("Origin Mode: ", barShapeComobo));
			}

            {
                NHScrollBar barWidthScrollBar = new NHScrollBar();
                barWidthScrollBar.Minimum = 0;
                barWidthScrollBar.Maximum = 100;
                barWidthScrollBar.ValueChanged += OnBarWidthScrollBarValueChanged;
                barWidthScrollBar.Value = 50;
                stack.Add(NPairBox.Create("Width Gap %: ", barWidthScrollBar));
            }

            {
                NHScrollBar barDepthScrollBar = new NHScrollBar();
                barDepthScrollBar.Minimum = 0;
                barDepthScrollBar.Maximum = 100;
                barDepthScrollBar.ValueChanged += OnBarDepthScrollBarValueChanged;
                barDepthScrollBar.Value = 50;
                stack.Add(NPairBox.Create("Depth Gap %: ", barDepthScrollBar));
            }

            {
				NButton positiveDataButton = new NButton("Positive Data");
                positiveDataButton.Click += OnPositiveDataButtonClick;
				stack.Add(positiveDataButton);
			}

            {
                NButton positiveAndNegativeData = new NButton("Positive and Negative Data");
                positiveAndNegativeData.Click += OnPositiveAndNegativeDataButtonClick;
                stack.Add(positiveAndNegativeData);
            }

            return boxGroup;
		}
        public string GetExampleDescription()
		{
			return @"

This example demonstrates a Manhattan bar chart. This type of chart is created with several bar series displayed with the MultiBarMode property set to Series.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Bar Series", "https://www.nevron.com/docs/openvision/bar-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnBarWidthScrollBarValueChanged(NValueChangeEventArgs arg) { double gapFactor = (double)arg.NewValue / 100; m_Bar1.WidthGapFactor = gapFactor; m_Bar2.WidthGapFactor = gapFactor; m_Bar3.WidthGapFactor = gapFactor; m_Bar4.WidthGapFactor = gapFactor; } private void OnBarDepthScrollBarValueChanged(NValueChangeEventArgs arg) { double gapFactor = (double)arg.NewValue / 100; m_Bar1.DepthGapFactor = gapFactor; m_Bar2.DepthGapFactor = gapFactor; m_Bar3.DepthGapFactor = gapFactor; m_Bar4.DepthGapFactor = gapFactor; } private void OnPositiveDataButtonClick(NEventArgs arg) { m_Bar1.DataPoints.Clear(); m_Bar2.DataPoints.Clear(); m_Bar3.DataPoints.Clear(); m_Bar4.DataPoints.Clear(); Random random = new Random(); for (int i = 0; i < 6; i++) { m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(100))); m_Bar2.DataPoints.Add(new NBarDataPoint(random.Next(100))); m_Bar3.DataPoints.Add(new NBarDataPoint(random.Next(100))); m_Bar4.DataPoints.Add(new NBarDataPoint(random.Next(100))); } } private void OnPositiveAndNegativeDataButtonClick(NEventArgs arg) { m_Bar1.DataPoints.Clear(); m_Bar2.DataPoints.Clear(); m_Bar3.DataPoints.Clear(); m_Bar4.DataPoints.Clear(); Random random = new Random(); for (int i = 0; i < 12; i++) { m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(100) - 50)); m_Bar2.DataPoints.Add(new NBarDataPoint(random.Next(100) - 50)); m_Bar3.DataPoints.Add(new NBarDataPoint(random.Next(100) - 50)); m_Bar4.DataPoints.Add(new NBarDataPoint(random.Next(100) - 50)); } } private void OnBarShapeComoboSelectedIndexChanged(NValueChangeEventArgs arg) { m_Bar1.Shape = (ENBarShape)arg.NewValue; m_Bar2.Shape = (ENBarShape)arg.NewValue; m_Bar3.Shape = (ENBarShape)arg.NewValue; m_Bar4.Shape = (ENBarShape)arg.NewValue; } #endregion #region Fields private NCartesianChart m_Chart; private NBarSeries m_Bar1; private NBarSeries m_Bar2; private NBarSeries m_Bar3; private NBarSeries m_Bar4; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Manhattan Bar Example for WPF Solution

VB.NET Manhattan Bar Example Code for Nevron Chart for WPF
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.Wpf
Imports System

Class MainWindow

#Region "Constructors"

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

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NManhattanBarExample"

		' 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)
		Content = 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 = "Manhattan Bar Chart"

            ' 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.Labels.TextProvider = New NOrdinalScaleLabelTextProvider(New String() {"Chicago", "Los Angeles", "Miami", "New York"})
            ordinalScale.DisplayDataPointsBetweenTicks = True
            ordinalScale.Labels.Style.Angle = New NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0)

            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
            m_Bar1 = New NBarSeries()
            m_Chart.Series.Add(m_Bar1)
            m_Bar1.MultiBarMode = ENMultiBarMode.Series
            m_Bar1.Name = "Bar1"
            m_Bar1.Stroke = New NStroke(1, NColor.FromRGB(210, 210, 255))

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

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

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

            OnPositiveDataButtonClick(Nothing)

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

            If True Then
                Dim barShapeComobo As NComboBox = New NComboBox()
                barShapeComobo.Items.FillFromEnum(Of ENBarShape)()
                barShapeComobo.SelectedIndexChanged += AddressOf OnBarShapeComoboSelectedIndexChanged
                barShapeComobo.SelectedIndex = CInt(ENBarShape.Rectangle)
                stack.Add(NPairBox.Create("Origin Mode: ", barShapeComobo))
            End If

            If True Then
                Dim barWidthScrollBar As NHScrollBar = New NHScrollBar()
                barWidthScrollBar.Minimum = 0
                barWidthScrollBar.Maximum = 100
                barWidthScrollBar.ValueChanged += AddressOf OnBarWidthScrollBarValueChanged
                barWidthScrollBar.Value = 50
                stack.Add(NPairBox.Create("Width Gap %: ", barWidthScrollBar))
            End If

            If True Then
                Dim barDepthScrollBar As NHScrollBar = New NHScrollBar()
                barDepthScrollBar.Minimum = 0
                barDepthScrollBar.Maximum = 100
                barDepthScrollBar.ValueChanged += AddressOf OnBarDepthScrollBarValueChanged
                barDepthScrollBar.Value = 50
                stack.Add(NPairBox.Create("Depth Gap %: ", barDepthScrollBar))
            End If

            If True Then
                Dim positiveDataButton As NButton = New NButton("Positive Data")
                positiveDataButton.Click += AddressOf OnPositiveDataButtonClick
                stack.Add(positiveDataButton)
            End If

            If True Then
                Dim positiveAndNegativeData As NButton = New NButton("Positive and Negative Data")
                positiveAndNegativeData.Click += AddressOf OnPositiveAndNegativeDataButtonClick
                stack.Add(positiveAndNegativeData)
            End If

            Return boxGroup
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates a Manhattan bar chart. This type of chart is created with several bar series displayed with the MultiBarMode property set to Series.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Bar Series", "https://www.nevron.com/docs/openvision/bar-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnBarWidthScrollBarValueChanged(arg As NValueChangeEventArgs) Dim gapFactor = CDbl(arg.NewValue) / 100 m_Bar1.WidthGapFactor = gapFactor m_Bar2.WidthGapFactor = gapFactor m_Bar3.WidthGapFactor = gapFactor m_Bar4.WidthGapFactor = gapFactor End Sub Private Sub OnBarDepthScrollBarValueChanged(arg As NValueChangeEventArgs) Dim gapFactor = CDbl(arg.NewValue) / 100 m_Bar1.DepthGapFactor = gapFactor m_Bar2.DepthGapFactor = gapFactor m_Bar3.DepthGapFactor = gapFactor m_Bar4.DepthGapFactor = gapFactor End Sub Private Sub OnPositiveDataButtonClick(arg As NEventArgs) m_Bar1.DataPoints.Clear() m_Bar2.DataPoints.Clear() m_Bar3.DataPoints.Clear() m_Bar4.DataPoints.Clear() Dim random As Random = New Random() For i = 0 To 5 m_Bar1.DataPoints.Add(New NBarDataPoint(random.Next(100))) m_Bar2.DataPoints.Add(New NBarDataPoint(random.Next(100))) m_Bar3.DataPoints.Add(New NBarDataPoint(random.Next(100))) m_Bar4.DataPoints.Add(New NBarDataPoint(random.Next(100))) Next End Sub Private Sub OnPositiveAndNegativeDataButtonClick(arg As NEventArgs) m_Bar1.DataPoints.Clear() m_Bar2.DataPoints.Clear() m_Bar3.DataPoints.Clear() m_Bar4.DataPoints.Clear() Dim random As Random = New Random() For i = 0 To 11 m_Bar1.DataPoints.Add(New NBarDataPoint(random.Next(100) - 50)) m_Bar2.DataPoints.Add(New NBarDataPoint(random.Next(100) - 50)) m_Bar3.DataPoints.Add(New NBarDataPoint(random.Next(100) - 50)) m_Bar4.DataPoints.Add(New NBarDataPoint(random.Next(100) - 50)) Next End Sub Private Sub OnBarShapeComoboSelectedIndexChanged(arg As NValueChangeEventArgs) m_Bar1.Shape = CType(arg.NewValue, ENBarShape) m_Bar2.Shape = CType(arg.NewValue, ENBarShape) m_Bar3.Shape = CType(arg.NewValue, ENBarShape) m_Bar4.Shape = CType(arg.NewValue, ENBarShape) End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart Private m_Bar1 As NBarSeries Private m_Bar2 As NBarSeries Private m_Bar3 As NBarSeries Private m_Bar4 As NBarSeries #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) Manhattan Bar Example for WPF Solution

Related Documentation Links