<Grid x:Name="grid"> <Grid.DataContext> <local:DataViewModel/> </Grid.DataContext>22 <chart:SfChart> <chart:ColumnSeries ItemsSource="{Binding Data}" XBindingPath="ProductName" YBindingPath="UnitsInStock"></chart:ColumnSeries> </chart:SfChart> </Grid> |
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | public class DataViewModel { DataSet dataset = new DataSet(); public DataViewModel() { AddData(); } public void AddData() { //Sets Database connection. string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", @"..\..\Model\DataBase_File.mdb"); OleDbConnection Connection = new OleDbConnection(connectionString); Connection.Open(); OleDbCommand command = new OleDbCommand("Select Top 10 * from [Products]", Connection); OleDbDataAdapter DataAdapter = new OleDbDataAdapter(command); DataAdapter.Fill(dataset, "Product"); //Sets the DataTable to Data property. this.Data = dataset.Tables["Product"]; Connection.Close(); } public DataTable _data; public DataTable Data { get { return _data; } set { _data = value; } } }/////////////////////////////////////////// |
|
DispatcherTimer timer = new DispatcherTimer();
DataViewModel viewModel = new DataViewModel();
Random rd = new Random();
string[] names;
public MainWindow()
{
InitializeComponent();
series.ItemsSource = viewModel.Data;
names = new string[] { "Chang", "Ikura", "Kobe", "Peas", "Pepper" };
timer.Start();
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
}
void timer_Tick(object sender, EventArgs e)
{
viewModel.Data.Rows.RemoveAt(0);
viewModel.Data.Rows.Add(new Object[] { names[rd.Next(0,4)], rd.Next(4,20) });
} |
|
public MainWindow()
{
InitializeComponent();
//Sets Database connection.
string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", @"DataBase_File.mdb");
Connection = new OleDbConnection(connectionString);
Connection.Open();
..
EngAsync();
Connection.Close();
}
private void dataGridViewX()
{
OleDbCommand command = new OleDbCommand("Select Top 10 * from [Data]", Connection);
OleDbDataAdapter DataAdapter = new OleDbDataAdapter(command);
DataAdapter.Fill(dataset, "Data");
//Sets the DataTable to Data property.
Data = dataset.Tables["Data"];
dataGrid2xc.ItemsSource = Data.DefaultView;
}
private void PaymentsCompletedX()
{
OleDbCommand command = new OleDbCommand("Select Top 10 * from [Data]", Connection);
OleDbDataAdapter DataAdapter = new OleDbDataAdapter(command);
DataAdapter.Fill(dataset, "Data");
//Sets the DataTable to Data property.
Data = dataset.Tables["Data"];
dataGrid2xy.ItemsSource = Data.DefaultView;
} |