2010-02-12 24 views
1

Silverlight 3工具包圖表非常棒。我正在使用BarSeries,silverlight顯示的是與值邊界成比例的條的長度。但是有什麼辦法可以在酒吧或酒吧旁邊獲得實際價值嗎?這裏是我的XAMLSilverlight 3工具包圖表:如何顯示欄上的值?

<chartingToolkit:Chart 
         Grid.Column="1" 
         x:Name="chartEnvironmentStatusGlobal" 
         Title="Environment Status"> 
         <chartingToolkit:BarSeries 
          x:Name="chartEnvironmentStatus" 
          Title="Pass" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Stretch" 
          Background="Green" 
          IndependentValueBinding="{Binding Path=Instance}" 
          DependentValueBinding="{Binding Path=Count}" 
          AnimationSequence="LastToFirst"> 
          </chartingToolkit:BarSeries> 
         <chartingToolkit:BarSeries 
          x:Name="chartEnvironmentStatus1" 
          Title="Fail" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Stretch" 
          Background="Red" 
          IndependentValueBinding="{Binding Path=Instance}" 
          DependentValueBinding="{Binding Path=Count}" 
          AnimationSequence="LastToFirst"> 
          </chartingToolkit:BarSeries> 
        </chartingToolkit:Chart> 

在此先感謝您。

回答

2

您將需要爲BarDataPoint創建一個新模板。我不會在這裏發佈整個模板,因爲a)它相當大,b)我不確定版權所在。

如果你有混合,你可以很容易地獲得現有的模板,應該可以使用該工具創建副本。另外,您可以從源代碼得到它的發現: -

#someSourceCodeRootFolder\Controls.DataVisualization.Toolkit\Charting\DataPoint\BarDataPoint.xaml 

在資源字典創建此: -

<Style x:Key="BarDataPointWithContent" TargetType="charting:BarDataPoint"> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <Border ... copy from original template... > 
     <!-- Wads of original VisualStateManager stuff here --> 
     <Grid Background="{TemplateBinding Background}"> 
      <!-- Original set of Rectangles and Border here --> 
      <TextBlock Text="{TemplateBinding FormattedDependentValue}" 
      HorizontalAlignment="Center" /> 
     </Grid> 
     <ToolTipService.ToolTip> 
      <!-- Do something different here perhaps --> 
     </ToolTipService.ToolTip> 
     </Border> 
    </Setter.Value> 
    </Setter> 
</Style> 

基本上我做了什麼補充的是,最終TextBlock和束縛到工具提示在其ContentControl中使用的相同FormattedDependentValue屬性。您可以在TextBlock中添加更多樣式以獲得所需的外觀,您也可能希望對工具提示內容做一些不同的操作。

所以這種風格閒逛,你可以在圖表本身做到這一點: -

<chartingToolkit:BarSeries.DataPointStyle> 
    <Style TargetType="BarDataPoint" BasedOn="{StaticResouce BarDataPointWithContent}" > 
    <Setter Property="Background" Value="Red" /> 
    </Style> 
</chartingToolkit:BarSeries.DataPointStyle> 

注意,以潛伏MSofties

能否請你的模板添加到文檔的某個地方,讓我們不需要源代碼,Blend或Reflector來提取它們?

+0

工作就像魅力!非常感謝你。 Silverlight模板非常棒。 – funwithcoding 2010-02-12 22:14:14

+0

你可能想試試http://blogs.msdn.com/delay/archive/2008/12/14/expanded-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-updated-for -better-compatibility.aspx來提取模板 – Jags 2011-06-14 11:08:34