Drawing scatter point plot in wpf application

Tan, Thuan Seah 20 Reputation points
2023-05-03T04:47:44.2933333+00:00

Does Microsoft have an official control for drawing scatter plot? I did a search and System.Windows.Controls.DataVisualization.Toolkit seems to come up a fair bit but I couldn't seem to find where to download this library. Is my best bet to use the System.Windows.Forms.DataVisualization one if I don't want to rely on 3rd party libraries?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,850 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
805 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,491 Reputation points Microsoft Vendor
    2023-05-03T10:03:45.79+00:00

    Hi,@Tan, Thuan Seah. Welcome Microsoft Q&A.

    Microsoft does not have an official control for drawing scatter plots in WPF. The System.Windows.Controls.DataVisualization.Toolkit library you mentioned package only contains assemblies for the .NET Framework 4.0 Client Profile. Therefore, it is not compatible with any version of .NET Core.

    Since this package is not an official Microsoft package and there are no updates for .NET Core

    If you prefer not to use third-party libraries, you could use the System.Windows.Forms.DataVisualization library as Castorix31 said, which is part of the .NET Framework and includes a Chart control that can be used to draw scatter plots.

    First, add references to the following assemblies to your WPF project.

    • System.Windows.Forms.DataVisualization
    • System.Windows.Forms.DataVisualization.Design
    • System.Windows.Forms
    • WindowsFormsIntegration

    MainWindow.xaml:

    <Grid x:Name="grid">
            
        </Grid>
    
    

    MainWindow.xaml.cs:

    
    using System.Windows;
    using System.Windows.Forms.DataVisualization.Charting;
    
    namespace WpfApp3
    {
        public partial class MainWindow : Window
        {
    
            Chart chart1 = new Chart();
            public MainWindow()
            {
                InitializeComponent();
    
                System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
    
                draw();
                chart1.Titles.Add(" Chart");
                host.Child = chart1;
                grid.Children.Add(host);
            }
            public Chart draw()
            {
                ChartArea ChartArea1 = new ChartArea();
                this.chart1.ChartAreas.Add("ChartArea1");
                this.chart1.Series.Add("series");
                this.chart1.Series[0].Points.AddXY(1, 5);
                this.chart1.Series[0].Points.AddXY(2, 4);
                this.chart1.Series[0].Points.AddXY(3, 3);
                this.chart1.Series[0].Points.AddXY(4, 2);
                this.chart1.Series[0].Points.AddXY(5, 1);
    
    
                return chart1;
            }
        }
    }
    
    

    The result:

    User's image


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 84,546 Reputation points
    2023-05-03T06:26:54.2233333+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.