Chart Themes 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.

Chart Themes Example for WPF Description

This example demonstrates how to apply different chart color themes.


Chart Themes Example

C# Chart Themes 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 - NChartThemesExample";

			// 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();
			m_ChartView = chartViewWithCommandBars.View;
			m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

			// configure title
			m_ChartView.Surface.Titles[0].Text = "Chart Themes";

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

			// add interlace stripe
			NLinearScale linearScale = chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
			NScaleStrip strip = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1);
			strip.Interlaced = true;
			linearScale.Strips.Add(strip);

			// add a bar series
			Random random = new Random();
			for (int i = 0; i < 6; i++)
			{
				NBarSeries bar = new NBarSeries();
				bar.Name = "Bar" + i.ToString();
				bar.MultiBarMode = ENMultiBarMode.Clustered;
				bar.DataLabelStyle = new NDataLabelStyle(false);
				bar.ValueFormatter = new NNumericValueFormatter("0.###");
				chart.Series.Add(bar);

				for (int j = 0; j < 6; j++)
				{
					bar.DataPoints.Add(new NBarDataPoint(random.Next(10, 100)));
				}
			}

			m_ChartView.Document.StyleSheets.ApplyTheme(new NChartTheme(DefaultChartPalette, ENChartPaletteTarget.Series));

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

			m_ChartPaletteComboBox = new NComboBox();
			m_ChartPaletteComboBox.Items.FillFromEnum();
			m_ChartPaletteComboBox.SelectedIndexChanged += OnChartPaletteComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Palette:", m_ChartPaletteComboBox));

			m_ChartPaletteTargetComboBox = new NComboBox();
			m_ChartPaletteTargetComboBox.Items.FillFromEnum();
			m_ChartPaletteTargetComboBox.SelectedIndexChanged += OnChartPaletteComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Target:", m_ChartPaletteTargetComboBox));

			m_ChartPaletteComboBox.SelectedIndex = (int)DefaultChartPalette;
			m_ChartPaletteTargetComboBox.SelectedIndex = (int)ENChartPaletteTarget.DataPoints;

			return new NUniSizeBoxGroup(stack);
		}

		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to apply different chart color themes.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Chart Themes", "https://www.nevron.com/docs/openvision/chart-themes.html"), ("Chart Overview", "https://www.nevron.com/docs/openvision/chart-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnChartPaletteComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_ChartView.Document.StyleSheets.ApplyTheme(new NChartTheme((ENChartPalette)m_ChartPaletteComboBox.SelectedIndex, (ENChartPaletteTarget)m_ChartPaletteTargetComboBox.SelectedIndex)); } #endregion #region Fields private NChartView m_ChartView; private NComboBox m_ChartPaletteComboBox; private NComboBox m_ChartPaletteTargetComboBox; #endregion #region Static Methods #endregion #region Constants private const ENChartPalette DefaultChartPalette = ENChartPalette.Autumn; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Chart Themes Example for WPF Solution

VB.NET Chart Themes 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 - NChartThemesExample"

		' 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()
            m_ChartView = chartViewWithCommandBars.View
            m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            ' configure title
            m_ChartView.Surface.Titles(0).Text = "Chart Themes"

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

            ' add interlace stripe
            Dim linearScale As NLinearScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
            Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1)
            strip.Interlaced = True
            linearScale.Strips.Add(strip)

            ' add a bar series
            Dim random As Random = New Random()
            For i = 0 To 5
                Dim bar As NBarSeries = New NBarSeries()
                bar.Name = "Bar" & i.ToString()
                bar.MultiBarMode = ENMultiBarMode.Clustered
                bar.DataLabelStyle = New NDataLabelStyle(False)
                bar.ValueFormatter = New NNumericValueFormatter("0.###")
                chart.Series.Add(bar)

                For j = 0 To 5
                    bar.DataPoints.Add(New NBarDataPoint(random.Next(10, 100)))
                Next
            Next

            m_ChartView.Document.StyleSheets.ApplyTheme(New NChartTheme(DefaultChartPalette, ENChartPaletteTarget.Series))

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

            m_ChartPaletteComboBox = New NComboBox()
            m_ChartPaletteComboBox.Items.FillFromEnum(Of ENChartPalette)()
            Me.m_ChartPaletteComboBox.SelectedIndexChanged += AddressOf OnChartPaletteComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Palette:", m_ChartPaletteComboBox))

            m_ChartPaletteTargetComboBox = New NComboBox()
            m_ChartPaletteTargetComboBox.Items.FillFromEnum(Of ENChartPaletteTarget)()
            Me.m_ChartPaletteTargetComboBox.SelectedIndexChanged += AddressOf OnChartPaletteComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Target:", m_ChartPaletteTargetComboBox))

            m_ChartPaletteComboBox.SelectedIndex = CInt(DefaultChartPalette)
            m_ChartPaletteTargetComboBox.SelectedIndex = CInt(ENChartPaletteTarget.DataPoints)

            Return New NUniSizeBoxGroup(stack)
        End Function

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to apply different chart color themes.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Chart Themes", "https://www.nevron.com/docs/openvision/chart-themes.html"), ("Chart Overview", "https://www.nevron.com/docs/openvision/chart-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnChartPaletteComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_ChartView.Document.StyleSheets.ApplyTheme(New NChartTheme(CType(m_ChartPaletteComboBox.SelectedIndex, ENChartPalette), CType(m_ChartPaletteTargetComboBox.SelectedIndex, ENChartPaletteTarget))) End Sub #End Region #Region "Fields" Private m_ChartView As NChartView Private m_ChartPaletteComboBox As NComboBox Private m_ChartPaletteTargetComboBox As NComboBox #End Region #Region "Static Methods" #End Region #Region "Constants" Private Const DefaultChartPalette As ENChartPalette = ENChartPalette.Autumn #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Chart Themes Example for WPF Solution

Related Documentation Links