2012-02-06 4 views
0

を表示しません、私はどこにでもXAMLでそれの証拠は、実行時にチャートの100%を作成しようとしています。ページのロード時にそうするために、私は空白のチャートを作成:のSilverlight 4のチャートは、Silverlightの4ツールキットのチャートコントロールを使用してデータ

 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; } 
    } 

私のチャートのItemsSourceとして、CurrentCallTrendsと呼ばれるそのリスト。

 // 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は消滅し、データは表示されませんが、少なくとも実行時エラーはありません。

私には何が欠けていますか?

+0

「CurrentCallTrends」とは何ですか? – ChrisF

+0

私はこれをクラスのトップに宣言しました。これは次のとおりです。プライベートList CurrentCallTrends =新しいList (); –

答えて

0

追加Googleをした後、私は動作するようですが、これをやって行くための最善の方法として私を打つていないいくつかの変更を行いました。データが表示されるようになりましたが、より良い方法がない限り、回答として受け付けません。

 // Update the chart with the received data 
     Chart TrendChart = (Chart)this.FindName("TrendChart"); 

     // Wipe out previous chart data 
     TrendChart.Series.Clear(); 


     // test data 
     KeyValuePair<string, double>[] CurrentCallData = new KeyValuePair<string, double>[CurrentCallTrends.Count]; 
     for (int i = 0; i < CurrentCallTrends.Count; i++) 
     { 
      CurrentCallData[i] = new KeyValuePair<string, double>(CurrentCallTrends[i].XValue, CurrentCallTrends[i].YValue); 
     } 



     // set the data 
     ColumnSeries columnSeries = new ColumnSeries(); 
     columnSeries.Name = "CurrentCallVolume"; 
     columnSeries.Title = "Current Call Volume"; 
     columnSeries.SetBinding(ColumnSeries.ItemsSourceProperty, new Binding()); 
     //columnSeries.ItemsSource = CurrentCallTrends; 
     columnSeries.ItemsSource = CurrentCallData; 
     columnSeries.DependentValueBinding = new Binding("Value"); 
     columnSeries.IndependentValueBinding = new Binding("Key"); 
     TrendChart.Series.Add(columnSeries); 

     //this.DataContext = CurrentCallTrends; 
関連する問題