Add NOV Chart control in MonoMac project at runtime
To get started and host NOV in your Mac OS X (MonoMac) application, take a look at:
Getting Started with NOV in MonoMac project
The following topic shows how to add a NOV Chart Widget (control) in MonoMac project at runtime.
1. Reference the NOV Assemblies
Ensure that your application references the following NOV dlls:
Nevron.Nov.Presentation.dll - core NOV portable assembly;
Nevron.Nov.Host.MonoMac.dll - presentation host for MonoMac;
MonoMac.dll - make sure to reference the MonoMac.dll that comes with the NOV installation and remove the default one, which is created by Xamarin Studio;
Nevron.Nov.Chart.dll - assembly for the NChartModule;
You can reference the dlls directly from the System/Applications/NevronOpenVision.MonoMac.app/Contents/Bin folder or copy those dlls to a folder which is more convenient for referencing.
2. When initializing the NOV Application, make sure to create the Chart module
Open the Main.cs file and use the following code:
using
System;
using
Nevron.Nov;
using
Nevron.Nov.Mac;
using
Nevron.Nov.Chart;
#if UNIFIEDAPI
using
Foundation;
using
AppKit;
#else
using
MonoMac.Foundation;
using
MonoMac.AppKit;
#endif
namespace
MonoMacApplication1
{
class
MainClass
{
static
void
Main(
string
[] args)
{
NSApplication.Init();
NLicenseManager.Instance.SetLicense(
new
NLicense(
"LICENSE KEY"
));
// install NOV
NModule[] modules =
new
NModule[]
{
// TODO: Create modules here
NChartModule.Instance
};
NNOVApplicationInstaller.Install(modules);
NSApplication.Main(args);
}
}
}
3. Create the Chart View and setup a Bar series
Open the MainWindow.cs file and use the following code to create the Chart:
using
System;
using
Nevron.Nov.Mac;
using
Nevron.Nov.UI;
using
Nevron.Nov;
using
Nevron.Nov.Chart;
using
Nevron.Nov.Graphics;
#if UNIFIEDAPI
using
Foundation;
using
AppKit;
#else
using
MonoMac.Foundation;
using
MonoMac.AppKit;
#endif
namespace
MonoMacApplication1
{
public
partial
class
MainWindow : NSWindow
{
#region Constructors
// Called when created from unmanaged code
public
MainWindow(IntPtr handle)
:
base
(handle)
{
Initialize();
}
// Called when created directly from a XIB file
[Export(
"initWithCoder:"
)]
public
MainWindow(NSCoder coder)
:
base
(coder)
{
Initialize();
}
// Shared initialization code
void
Initialize()
{
NApplication.ApplyTheme(
new
NMacElCapitanTheme());
// create chart
NChartView chartView =
new
NChartView();
chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);
// configure chart title
chartView.Surface.Titles[0].Text =
"Standard Bar"
;
// configure chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
// 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);
// setup a bar series
NBarSeries bar =
new
NBarSeries();
bar.Name =
"Bar Series"
;
bar.InflateMargins =
true
;
bar.UseXValues =
false
;
bar.Shadow =
new
NShadow(NColor.LightGray, 2, 2);
// add some data to the bar series
bar.LegendView.Mode = ENSeriesLegendMode.DataPoints;
bar.DataPoints.Add(
new
NBarDataPoint(18,
"C++"
));
bar.DataPoints.Add(
new
NBarDataPoint(15,
"Ruby"
));
bar.DataPoints.Add(
new
NBarDataPoint(21,
"Python"
));
bar.DataPoints.Add(
new
NBarDataPoint(23,
"Java"
));
bar.DataPoints.Add(
new
NBarDataPoint(27,
"Javascript"
));
bar.DataPoints.Add(
new
NBarDataPoint(29,
"C#"
));
bar.DataPoints.Add(
new
NBarDataPoint(26,
"PHP"
));
chart.Series.Add(bar);
// create NOV host
this
.ContentView =
new
NNovWidgetHost(
chartView);
}
#endregion
}
}
Run the application - it should display a simple Mac window with a Bar Chart series.
For more information about the NOV Chart component, take a look at the Help Documentation:
Chart > Chart Overview
Article ID: 250, Created On: 8/12/2016, Modified: 8/12/2016