Under .NET there are
many libraries for graphing. The choice towards a Microsoft solution was bribed by the fact that it is built into the .NET Framework 4 and therefore does not require the inclusion of third-party libraries. Although there is one drawback - you can work with it only on the Windows Forms form, for WPF forms of regular work with the component is not provided. Because of this, all the manuals, beginning with the words “drag the Chart component onto the form”,
went in the forest did not help at all to solve the problem.
First, it was necessary to decide how to use Windows Forms components on the WPF form. To do this,
judging by the instructions from MSDN, you need to add a link to the
Windows FormsIntegration and to
System.Windows.Forms . You also need to add their namespaces to the <Window> element of the XAML document of the form, and the <WindowsFormsHost> element, which will later house the necessary Windows Forms component:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"> <StackPanel> <WindowsFormsHost></WindowsFormsHost> </StackPanel> </Window>
')
Now everything is ready to use Windows Forms components, but all the work on implementing the component on the form will have to be done manually. Connect to the
System.Windows.Forms.DataVisualization.Charting project, add the namespace to the XAML document and the component itself on the form.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ... xmlns:dvc="clr-namespace:System.Windows.Forms.DataVisualization.Charting; assembly=System.Windows.Forms.DataVisualization"> <StackPanel> <WindowsFormsHost><dvc:Chart x:Name="chart" /></WindowsFormsHost> </StackPanel> </Window>
There is a
wonderful project from Microsoft , containing a lot of examples of working with the Chart component for Windows Forms. But it will not be possible to start it right away, since the environment necessary for initializing a component under Windows Forms is generated by the environment in the InitializeComponent () method on the basis of the component settings made by the developer. I did not find a way to call the component configurator for the WPF form, so before using the code from the examples, I’ll have to manually add a couple of lines of code.
using System.Windows.Forms.DataVisualization.Charting; ... private void Window_Loaded(object sender, RoutedEventArgs e) {
As a result, we get a wonderful schedule, and most importantly, no third-party libraries:
