我在silverlight中有这个简单的图表:
<toolkit:Chart HorizontalAlignment="Left" Margin="0,10,0,0" Title="Chart Title" VerticalAlignment="Top" Height="280" Width="390" Name="MyChart">
<toolkit:ColumnSeries DependentValuePath="X" IndependentValuePath="Y">
<toolkit:ColumnSeries.ItemsSource>
<PointCollection x:Name="PointColl">
<Point>1,10</Point>
<Point>2,20</Point>
<Point>3,30</Point>
<Point>4,40</Point>
</PointCollection>
</toolkit:ColumnSeries.ItemsSource>
</toolkit:ColumnSeries>
</toolkit:Chart>
并在代码中设置数据绑定,如下所示:
private ObservableCollection<Point> _myPointCollection = new ObservableCollection<Point>();
public ObservableCollection<Point> MyPointCollection { get { return _myPointCollection; } }
public MainPage()
{
InitializeComponent();
rand = new Random();
MyPointCollection.Add( new Point(0, rand.Next(0, 50)));
MyPointCollection.Add( new Point(0, rand.Next(1, 50)));
MyPointCollection.Add( new Point(0, rand.Next(2, 50)));
MyPointCollection.Add( new Point(0, rand.Next(3, 50)));
MyChart.DataContext = this;
}
但是我在 xaml 中的什么位置告诉我在哪里绑定数据?