Page1.xaml
<sdk:Page 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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
mc:Ignorable="d"
x:Class="SilverlightApplication1.Page1"
Title="Page1 Page"
d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" >
<toolkit:Chart x:Name="chart1" Margin="8,8,8,72" Title="Chart Title">
</toolkit:Chart>
</Grid>
</sdk:Page>
Page1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Windows.Controls.DataVisualization.Charting.Compatible;
using System.Windows.Data;
namespace SilverlightApplication1
{
public partial class Page1 : Page
{
System.Windows.Threading.DispatcherTimer testDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
List<ChartData> testChartData = new List<ChartData>();
int num = 0;
public Page1()
{
InitializeComponent();
setTime();
}
private void setTime()
{
testDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1);
testDispatcherTimer.Tick += new EventHandler(testDispatcherTimer_Tick);
testDispatcherTimer.Start();
}
void testDispatcherTimer_Tick(object sender, EventArgs e)
{
num++;
loadDate(num.ToString(),num);
if (num >= 5)
{
testDispatcherTimer.Stop();
}
}
private void loadDate(string inputStr, int inputData)
{
testChartData.Add(new ChartData { xStr = inputStr, yDate = inputData });
drawChart();
}
private void drawChart()
{
ColumnSeries columnSeries = new ColumnSeries();
columnSeries.ItemsSource = testChartData;
columnSeries.DependentValueBinding = new Binding("yDate");
columnSeries.IndependentValueBinding = new Binding("xStr");
columnSeries.Title = "TitleTest";
this.chart1.Series.Add(columnSeries);
this.chart1.Title = "";
}
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
public class ChartData
{
public string xStr { get; set; }
public int yDate { get; set; }
}
}
}