This example demonstrates how to apply different chart color themes.

| 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
}
}