XY Scatter 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.

XY Scatter Bar Example for WPF Description

This example demonstrates how to create a XY scatter bar chart.


XYScatter Bar Example

C# XY Scatter Bar Example Code for Nevron Chart for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
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 - NXYScatterBarExample";

			// 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 = "XY Scatter Bar";

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

			chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

			// add interlaced stripe to the Y axis
			NScaleStrip stripStyle = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;
			chart.Axes[ENCartesianAxis.PrimaryY].Scale.Strips.Add(stripStyle);

			m_Bar = new NBarSeries();
			chart.Series.Add(m_Bar);

			m_Bar.DataLabelStyle = new NDataLabelStyle(false);
			m_Bar.InflateMargins = true;
			m_Bar.WidthSizeMode = ENBarSizeMode.Fixed;
			m_Bar.FixedWidth = 20;

			m_Bar.Name = "Bar Series";
			m_Bar.UseXValues = true;

			// add xy values
			m_Bar.DataPoints.Add(new NBarDataPoint(15, 10));
			m_Bar.DataPoints.Add(new NBarDataPoint(25, 23));
			m_Bar.DataPoints.Add(new NBarDataPoint(45, 12));
			m_Bar.DataPoints.Add(new NBarDataPoint(55, 21));
			m_Bar.DataPoints.Add(new NBarDataPoint(61, 16));
			m_Bar.DataPoints.Add(new NBarDataPoint(67, 19));
			m_Bar.DataPoints.Add(new NBarDataPoint(72, 11));

            return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
			
			NButton changeXValuesButton = new NButton("Change X Values");
			changeXValuesButton.Click += OnChangeXValuesButtonClick;
			stack.Add(changeXValuesButton);

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

This example demonstrates how to create a XY scatter bar chart.

"; } /// /// 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"), ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnChangeXValuesButtonClick(NEventArgs arg) { Random random = new Random(); m_Bar.DataPoints[0].X = random.Next(10); for (int i = 1; i < m_Bar.DataPoints.Count; i++) { m_Bar.DataPoints[i].X = m_Bar.DataPoints[i - 1].X + random.Next(1, 10); } } #endregion #region Fields NBarSeries m_Bar; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

VB.NET XY Scatter Bar Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
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 - NXYScatterBarExample"

		' 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 = "XY Scatter Bar"

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

            chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear)

            ' add interlaced stripe to the Y axis
            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True
            chart.Axes(ENCartesianAxis.PrimaryY).Scale.Strips.Add(stripStyle)

            m_Bar = New NBarSeries()
            chart.Series.Add(m_Bar)

            m_Bar.DataLabelStyle = New NDataLabelStyle(False)
            m_Bar.InflateMargins = True
            m_Bar.WidthSizeMode = ENBarSizeMode.Fixed
            m_Bar.FixedWidth = 20

            m_Bar.Name = "Bar Series"
            m_Bar.UseXValues = True

            ' add xy values
            m_Bar.DataPoints.Add(New NBarDataPoint(15, 10))
            m_Bar.DataPoints.Add(New NBarDataPoint(25, 23))
            m_Bar.DataPoints.Add(New NBarDataPoint(45, 12))
            m_Bar.DataPoints.Add(New NBarDataPoint(55, 21))
            m_Bar.DataPoints.Add(New NBarDataPoint(61, 16))
            m_Bar.DataPoints.Add(New NBarDataPoint(67, 19))
            m_Bar.DataPoints.Add(New NBarDataPoint(72, 11))

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

            Dim changeXValuesButton As NButton = New NButton("Change X Values")
            changeXValuesButton.Click += AddressOf OnChangeXValuesButtonClick
            stack.Add(changeXValuesButton)

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

This example demonstrates how to create a XY scatter bar chart.

" 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"), ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnChangeXValuesButtonClick(arg As NEventArgs) Dim random As Random = New Random() m_Bar.DataPoints(0).X = random.Next(10) For i = 1 To m_Bar.DataPoints.Count - 1 m_Bar.DataPoints(i).X = m_Bar.DataPoints(i - 1).X + random.Next(1, 10) Next End Sub #End Region #Region "Fields" Private m_Bar 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) XY Scatter Bar Example for WPF Solution