The NMathChart adapter class makes it easy to generate visualizations of NMath data in as little as one line of code. The Chart class that is created is a Windows Forms control, but this control can be included in a Windows Presentation Foundation application by using the WindowsFormsHost element.
To do so:
- Add references to these namespaces: System.Windows.Forms
System.Windows.Forms.Integration
- In the XAML markup for your WPF window (MainWindow.xaml for example), add a WindowsFormsHost element at the desired location, e.g:<Grid>
<WindowsFormsHost Name=”ChartHost”/>
</Grid>
- In the code-behind for the window (MainWindow.xaml.cs for example), set the Child property of the WindowsFormsHost to a Chart. For example:public MainWindow()
{
InitializeComponent();
ChartHost.Child = NMathChart.ToChart(NMathFunctions.CosFunction,
-Math.PI, Math.PI, 100 );
}
To see this in action, check out the sample code in the new Visualization Examples solution included in NMath 5.3. For more information about visualization of NMath data types, see:
- Whitepaper: NMath Visualization Using the Microsoft Chart Controls
- Whitepaper: NMath Stats Visualization Using the Microsoft Chart Controls
- the API docs for the
CenterSpace.NMath.Charting.Microsoft
namespace
One thought on “NMath Charts in WPF”