Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This example demonstrates how to bind the SQL Database in UWP Chart

NotificationsYou must be signed in to change notification settings

SyncfusionExamples/How-to-bind-the-SQL-Database-in-UWP-Chart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

This example illustrates 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()    {        try        {            SqlConnection thisConnection = new SqlConnection(ConnectionString);            thisConnection.Open();            string Get_Data = "SELECT * FROM ChartData";            SqlCommand cmd = thisConnection.CreateCommand();            cmd.CommandText = Get_Data;            SqlDataAdapter sda = new SqlDataAdapter(cmd);            DataSet ds = new DataSet();            sda.Fill(ds);            var table = ds.Tables[0];            this.DataTable = table;        }        catch        {            return;        }    }    public object DataTable { get; set; }    public static string ConnectionString    {        get        {            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.

<Grid>        <Grid.DataContext>            <local:ViewModel></local:ViewModel>        </Grid.DataContext>                <chart:SfChart Margin="10">                        <chart:SfChart.PrimaryAxis>                <chart:NumericalAxis RangePadding="Additional"/>            </chart:SfChart.PrimaryAxis>             <chart:SfChart.SecondaryAxis>                <chart:NumericalAxis RangePadding="Additional"/>            </chart:SfChart.SecondaryAxis>             <chart:ScatterSeries ItemsSource="{Binding DataTable}"                                 XBindingPath="xVal"                                  YBindingPath="yVal"/>        </chart:SfChart>        </Grid>

Output:

SQL DataBinding to UWP SfChart

KB article -How to bind the SQL Database in UWP Chart (SfChart)?

See also

How to bind the SQL Database to WPF Charts

About

This example demonstrates how to bind the SQL Database in UWP Chart

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp