Silverlight 4ツールキットのチャートコントロールを使用して、実行時にグラフを100%作成しようとしていますが、XAMLのどこにもその証拠はありません。これを行うには、ページが読み込まれるときに空のグラフを作成します。
Chart TrendChart = new Chart();
TrendChart.Name = "TrendChart";
TrendChart.Title = "Call History";
TrendChart.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
TrendChart.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
TrendChart.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
TrendChart.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch;
GridPanel.Children.Add(TrendChart);
ユーザーがボタンをクリックしてデータを取得すると、このカスタムクラスのリストが作成されます。
private class PhoneTrendDataPoint
{
public string XValue { get; set; }
public double YValue { get; set; }
}
CurrentCallTrendsというListをChartのItemsSourceとして使用します。
//Update the chart with the received data
Chart TrendChart = (Chart)this.FindName("TrendChart");
//Wipe out previous chart data
TrendChart.Series.Clear();
//set the data
ColumnSeries columnSeries = new ColumnSeries();
columnSeries.Name = "Current Call Volume";
columnSeries.ItemsSource = CurrentCallTrends;
//columnSeries.SetBinding(ColumnSeries.ItemsSourceProperty, new Binding("CurrentCallTrends"));
columnSeries.DependentValueBinding = new Binding("XValue");
columnSeries.IndependentValueBinding = new Binding("YValue");
TrendChart.Series.Add(columnSeries);
問題は、オブジェクトのインスタンスに設定されていないオブジェクト参照に関するデバッガを開くように要求するランタイムエラーが発生することです。私が行を.SetBindingにコメントすると、ItemsSourceは消滅し、データは表示されませんが、少なくとも実行時エラーはありません。
私は何が欠けていますか?