Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ public class ViewModel

![SQL DataBinding to WPF SfChart](https://user-images.githubusercontent.com/53489303/200743338-52fee1f9-d723-46b2-87ae-81da3b6e2067.png)

KB article - [How to bind the SQL Database to WPF Charts?](https://www.syncfusion.com/kb/11595/how-to-bind-the-sql-database-to-wpf-charts)
## Troubleshooting

#### Path too long exception

If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to a shorter name before building the project.

For more details, refer to the KB on [How to bind the SQL Database to WPF Charts](https://www.syncfusion.com/kb/11595/how-to-bind-the-sql-database-to-wpf-charts)
6 changes: 0 additions & 6 deletions SQLWithChart/App.config

This file was deleted.

7 changes: 2 additions & 5 deletions SQLWithChart/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace SQLWithChart
Expand All @@ -14,4 +10,5 @@ namespace SQLWithChart
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions SQLWithChart/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
8 changes: 5 additions & 3 deletions SQLWithChart/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SQLWithChart"
xmlns:chart="http://schemas.syncfusion.com/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">

<Grid>

<Grid.DataContext>
Expand All @@ -24,9 +25,10 @@
</chart:SfChart.SecondaryAxis>

<chart:ScatterSeries ItemsSource="{Binding DataTable}"
XBindingPath="xval"
YBindingPath="yval"/>
XBindingPath="xval"
YBindingPath="yval"/>
</chart:SfChart>

</Grid>

</Window>
46 changes: 2 additions & 44 deletions SQLWithChart/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand All @@ -27,40 +21,4 @@ public MainWindow()
InitializeComponent();
}
}

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
{
MessageBox.Show("DataBase Error");
}
}

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";
}
}
}
}
}
55 changes: 0 additions & 55 deletions SQLWithChart/Properties/AssemblyInfo.cs

This file was deleted.

71 changes: 0 additions & 71 deletions SQLWithChart/Properties/Resources.Designer.cs

This file was deleted.

117 changes: 0 additions & 117 deletions SQLWithChart/Properties/Resources.resx

This file was deleted.

Loading