2012-02-06 101 views
3

這裏是我的目標:綁定集合WPF工具包圖表

  • 使用WPF工具包,創建具有線性Y軸和一個DateTime範圍X軸的簡單柱形圖。
  • 將一組對象綁定到圖表。每個對象都有一個DateTime(X軸數據點)和Int32(Y軸數據點)屬性。

下面是我目前的XAML。下面的XAML有我想然而,圖表將不提供任何數據軸:

<chartingToolkit:Chart Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Name="ColumnChart" Title="Records Loaded By Date" 
    VerticalAlignment="Top" Height="262"> 
      <chartingToolkit:Chart.Axes> 
       <chartingToolkit:DateTimeAxis Interval="1" IntervalType="Days" x:Name="myDateTimeAxis" 
         Orientation="X" Title="Date"> 
        <chartingToolkit:DateTimeAxis.AxisLabelStyle> 
         <Style TargetType="chartingToolkit:DateTimeAxisLabel"> 
          <Setter Property="StringFormat" Value="{}{0:MM/dd}"/> 
         </Style> 
        </chartingToolkit:DateTimeAxis.AxisLabelStyle> 
       </chartingToolkit:DateTimeAxis> 
       <chartingToolkit:LinearAxis Orientation="Y" ShowGridLines="True" x:Name="myYAxis" 
          Title="Transactions Loaded"/> 
      </chartingToolkit:Chart.Axes> 
      <chartingToolkit:Chart.Series> 
       <chartingToolkit:ColumnSeries DependentValuePath="TransactionLoadCount" 
     IndependentValuePath="Date" ItemsSource="{Binding Path=LoadStats}" 
     IsSelectionEnabled="True"> 
       </chartingToolkit:ColumnSeries> 
      </chartingToolkit:Chart.Series> 
     </chartingToolkit:Chart> 

注:當我刪除XML部分<chartingToolkit:Chart.Axes>...</chartingToolkit:Chart.Axes>數據會出現但不是我喜歡的格式。

爲什麼圖表不顯示我的收集數據?

+0

http://stackoverflow.com/questions/4762455/wpf-toolkit-february-2010-release-chart-with-column-series-empty-when-itemssou 圖表似乎只有在有多個集合中的項目。我正在測試一個元素的集合。 – Josh 2012-02-06 18:05:20

+0

我從來沒有使用WPF的圖表控件,但我最終可能會最終。請讓我知道這個問題是怎麼回事。 – 2012-02-06 18:16:51

+1

@jberger - 我遇到的是工具包中的一個錯誤。錯誤是:如果我的集合中存在1個元素,那麼圖表將不會呈現任何數據。 當我的集合包含> 1個元素時,則按預期控制渲染。所以我想解決方法是確保你的集合有多個元素。祝你好運! – Josh 2012-02-06 19:32:02

回答

0

既然你找到了它,並將它發佈在評論中,我將擴展其他事情以尋找何時會發生此問題。 請注意,來到這裏的讀者,問題是綁定到控件的列表需要在集合中包含> 1 DateTime才能顯示圖表。這是WPF Toolkit庫中的一個錯誤。這可能會在當前/未來版本的WPF Toolkit中修復。

如果沒有解決您的問題:

  1. 觀看你的輸出窗口任何綁定表達式錯誤時,控制負荷。如果圖表的數據上下文設置正確,將項目源綁定到不可用的集合將導致問題。
  2. 確保在DateTime軸上使用的DateTime值具有跨越至少2天的值,或者您的間隔設置爲任何值。如果適用,請嘗試設置最大值或最小值。
  3. 使用消除過程來確定其X軸或Y軸是否導致問題。註釋掉X軸XAML並查看控件是否正確顯示Y軸。如果是這樣,註釋掉Y軸並取消X軸XAML的註釋並查看它是否正確顯示。如果不是,你知道你的問題是與其中一個軸(沒有註釋掉)。
  4. 檢查您的StringFormat是否正確。在這裏,我相信你可以使用'Value =「MM/dd」
  5. 確保你正確拼寫了你的屬性IndependentValuePathDependentValuePath

我發現這些是圖表製作過程中遇到的最大問題,因此這是調試問題時要遵循的清單。希望這會回答很多一般性問題。如果它不足以作爲答案,你應該自己回答OP。