1

Silverlight 3 工具包图表非常棒。我正在使用 BarSeries,silverlight 显示的条形长度与值绑定成正比。但是有什么方法可以在条形图上或在条形图旁边获得实际值?这是我的 XAML

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

先感谢您。

4

1 回答 1

2

You will need to create a new template for the BarDataPoint. I'll not post the whole template here because a) its quite large and b) I'm not sure where I stand on Copyright.

You can get the existing Template fairly easily if you have blend you should be able to create copy with the tool. Alternatively you can get it from the source code its found in:-

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

In a resource dictionary create this:-

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

Basically what I've done is added that final TextBlock and bound it to the same FormattedDependentValue property that the ToolTip uses in its ContentControl. You could add further styling to the TextBlock to get the appearance that you want, you may also wish to do something different with the tool tip content.

So with this style hanging about you can do this in the chart itself:-

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

Note to lurking MSofties

Can you please add the Templates to the documentation somewhere so that we don't need source code, Blend or Reflector to extract them?

于 2010-02-12T20:35:01.393 回答