We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind the SQL Database to WPF Charts?

Platform: WPF |
Control: SfChart

This article explains how to establish the SQL connection and bind the retrieving data from database in a step by step process.

Step 1: Retrieve the data table from the SQL DataSet using the connection string.

    public class ViewModel
        public ViewModel()
                SqlConnection thisConnection = new SqlConnection(ConnectionString);
                string Get_Data = "SELECT * FROM ChartData";
                SqlCommand cmd = thisConnection.CreateCommand();
                cmd.CommandText = Get_Data;
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                var table = ds.Tables[0];
                this.DataTable = table;
                MessageBox.Show("DataBase Error");
        public object DataTable { get; set; }
        public static string ConnectionString
                string currentDir = System.Environment.CurrentDirectory;
                currentDir = currentDir.Substring(0, currentDir.Length - 10) + "\\LocalDataBase";
                 return @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + currentDir + @"\SeriesItemsSource.mdf;Integrated Security=True";


Step 2: In the main page, initialize the SfChart control and bind the retrieved data.

        <chart:SfChart Margin="10">
                <chart:NumericalAxis RangePadding="Additional"/>
                <chart:NumericalAxis RangePadding="Additional"/>
            <chart:ScatterSeries ItemsSource="{Binding DataTable}"


SQL DataBinding to SfChart


Download complete sample here

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile