This example demonstrates how to create a table scale. The table scale is a type of categorical scale that allows the visualization of tabular data. It contains rows that show data for series in the chart or custom, user-specified data.

| 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 - NTableScaleExample";
// 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 = "Table Scale";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
// configure axes
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
m_Chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling);
// configure the y axis
NLinearScale linearScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
NScaleGridLines majorGrid = new NScaleGridLines();
majorGrid.Stroke = new NStroke(1, NColor.DarkGray, ENDashStyle.Dot);
linearScale.MajorGridLines = majorGrid;
// add a strip line style
NScaleStrip strip = new NScaleStrip();
strip.Fill = new NColorFill(NColor.Beige);
strip.Interlaced = true;
linearScale.Strips.Add(strip);
// add some random data
Random random = new Random();
// create two series with random data
NBarSeries alcoholSales = new NBarSeries();
alcoholSales.Name = "Alcohol";
alcoholSales.MultiBarMode = ENMultiBarMode.Stacked;
alcoholSales.DataLabelStyle = new NDataLabelStyle(false);
for (int i = 0; i < 12; i++)
{
alcoholSales.DataPoints.Add(new NBarDataPoint(random.Next(100), 12));
}
m_Chart.Series.Add(alcoholSales);
NBarSeries beveragesSales = new NBarSeries();
beveragesSales.Name = "Beverages";
beveragesSales.MultiBarMode = ENMultiBarMode.Stacked;
beveragesSales.DataLabelStyle = new NDataLabelStyle(false);
for (int i = 0; i < 12; i++)
{
beveragesSales.DataPoints.Add(new NBarDataPoint(random.Next(100)));
}
m_Chart.Series.Add(beveragesSales);
// setup X axis with table scale
NCartesianAxis axis = m_Chart.Axes[ENCartesianAxis.PrimaryX];
m_TableScale = new NTableScale();
axis.Scale = m_TableScale;
NCustomTableScaleRow customRow = new NCustomTableScaleRow();
customRow.Items = new NDomArray(new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" });
m_TableScale.Rows.Add(customRow);
for (int i = 0; i < m_Chart.Series.Count; i++)
{
NSeriesTableScaleRow row = new NSeriesTableScaleRow();
row.Series = m_Chart.Series[i];
m_TableScale.Rows.Add(row);
}
// Setup the stock series
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
///
///
///
///
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NCheckBox showRowInterlacingCheckBox = new NCheckBox("Show Row Interlacing");
showRowInterlacingCheckBox.CheckedChanged += OnShowRowInterlacingCheckBoxCheckedChanged;
stack.Add(showRowInterlacingCheckBox);
NCheckBox showColumnInterlacingCheckBox = new NCheckBox("Show Column Interlacing");
showColumnInterlacingCheckBox.CheckedChanged += OnShowColumnInterlacingCheckBoxCheckedChanged;
stack.Add(showColumnInterlacingCheckBox);
NCheckBox showLeftHeadersCheckBox = new NCheckBox("Show Left Headers");
showLeftHeadersCheckBox.CheckedChanged += OnShowLeftHeadersCheckBoxCheckedChanged;
showLeftHeadersCheckBox.Checked = false;
stack.Add(showLeftHeadersCheckBox);
NCheckBox showRightHeadersCheckBox = new NCheckBox("Show Right Headers");
showRightHeadersCheckBox.CheckedChanged += OnShowRightHeadersCheckBoxCheckedChanged;
showRightHeadersCheckBox.Checked = false;
stack.Add(showRightHeadersCheckBox);
NComboBox labelFormatComboBox = new NComboBox();
labelFormatComboBox.SelectedIndexChanged += OnLabelFormatComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Label Format:", labelFormatComboBox));
// init form controls
showRowInterlacingCheckBox.Checked = true;
showColumnInterlacingCheckBox.Checked = true;
showLeftHeadersCheckBox.Checked = true;
labelFormatComboBox.Items.Add("");
labelFormatComboBox.Items.Add("");
labelFormatComboBox.SelectedIndex = 0;
return boxGroup;
}
///
///
///
///
public string GetExampleDescription()
{
return @"This example demonstrates how to create a table scale. The table scale is a type of categorical scale that allows the visualization of tabular data. It contains rows that show data for series in the chart or custom, user-specified data.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Table Scale", "https://www.nevron.com/docs/openvision/table-scale.html"),
("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"),
("Label Formatting", "https://www.nevron.com/docs/openvision/chart-label-formatting.html"),
("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
///
///
///
///
private void OnShowRowInterlacingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
// row interlacing
if ((bool)arg.NewValue)
{
NTableInterlaceStyle interlaceStyle = new NTableInterlaceStyle();
interlaceStyle.Type = ENTableInterlaceStyleType.Row;
interlaceStyle.Length = 1;
interlaceStyle.Interval = 1;
interlaceStyle.Fill = new NColorFill(NColor.FromColor(NColor.Beige, 124));
m_TableScale.InterlaceStyles.Add(interlaceStyle);
}
else
{
for (int i = m_TableScale.InterlaceStyles.Count - 1; i >= 0; i--)
{
NTableInterlaceStyle interlaceStyle = m_TableScale.InterlaceStyles[i];
if (interlaceStyle.Type == ENTableInterlaceStyleType.Row)
{
m_TableScale.InterlaceStyles.RemoveAt(i);
break;
}
}
}
}
///
///
///
///
private void OnShowColumnInterlacingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
// col interlacing
if ((bool)arg.NewValue)
{
NTableInterlaceStyle interlaceStyle = new NTableInterlaceStyle();
interlaceStyle.Type = ENTableInterlaceStyleType.Column;
interlaceStyle.Length = 1;
interlaceStyle.Interval = 1;
interlaceStyle.Fill = new NColorFill(NColor.FromColor(NColor.Red, 124));
m_TableScale.InterlaceStyles.Add(interlaceStyle);
}
else
{
for (int i = m_TableScale.InterlaceStyles.Count - 1; i >= 0; i--)
{
NTableInterlaceStyle interlaceStyle = m_TableScale.InterlaceStyles[i];
if (interlaceStyle.Type == ENTableInterlaceStyleType.Column)
{
m_TableScale.InterlaceStyles.RemoveAt(i);
break;
}
}
}
}
///
///
///
///
private void OnShowLeftHeadersCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
for (int i = 0; i < m_TableScale.Rows.Count; i++)
{
NSeriesTableScaleRow seriesRow = m_TableScale.Rows[i] as NSeriesTableScaleRow;
if (seriesRow != null)
{
seriesRow.ShowLeftRowHeader = (bool)arg.NewValue;
}
}
}
///
///
///
///
private void OnShowRightHeadersCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
for (int i = 0; i < m_TableScale.Rows.Count; i++)
{
NSeriesTableScaleRow seriesRow = m_TableScale.Rows[i] as NSeriesTableScaleRow;
if (seriesRow != null)
{
seriesRow.ShowRightRowHeader = (bool)arg.NewValue;
}
}
}
///
///
///
///
private void OnLabelFormatComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
switch ((int)arg.NewValue)
{
case 0: // value
for (int i = 0; i < m_Chart.Series.Count; i++)
{
NSeries series = m_Chart.Series[i];
series.LegendView.Format = "";
}
break;
case 1: // percent
for (int i = 0; i < m_Chart.Series.Count; i++)
{
NSeries series = m_Chart.Series[i];
series.LegendView.Format = "";
}
break;
default:
NDebug.Assert(false);
break;
}
}
#endregion
#region Fields
NCartesianChart m_Chart;
NTableScale m_TableScale;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}