NMath Charts in WPF

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:

  1. Add references to these namespaces: System.Windows.Forms
    System.Windows.Forms.Integration
  2. 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>
  3. 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:

One thought on “NMath Charts in WPF

Leave a Reply

Your email address will not be published. Required fields are marked *

Top