none
怎么样将数值直接显示在柱子图上?[ RRS feed

  • 问题

  • [Silverlight 4]

    用toolkit:chart做了一个柱子图,,,不希望只是鼠标放上去才显示出 柱子的值

    怎么让 柱子的值 直接显示在柱子上呢?


    不吝赐教
    2010年9月24日 13:24

答案

  • 编辑ColumnDataPoint默认的style,添加一个textblock,绑定到FormattedDependentValue属性上。用Blend比较方便

     <Style x:Key="ColumnDataPointStyle1" TargetType="toolkit:ColumnDataPoint">
       <Setter Property="Background" Value="Orange"/>
       <Setter Property="BorderBrush" Value="Black"/>
       <Setter Property="BorderThickness" Value="1"/>
       <Setter Property="IsTabStop" Value="False"/>
       <Setter Property="Template">
        <Setter.Value>
         <ControlTemplate TargetType="toolkit:ColumnDataPoint">
          <Border x:Name="Root" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0">
           <ToolTipService.ToolTip>
            <ContentControl Content="{TemplateBinding FormattedDependentValue}"/>
           </ToolTipService.ToolTip>
           <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
             <VisualStateGroup.Transitions>
              <VisualTransition GeneratedDuration="0:0:0.1"/>
             </VisualStateGroup.Transitions>
             <VisualState x:Name="Normal"/>
             <VisualState x:Name="MouseOver">
              <Storyboard>
               <DoubleAnimation Duration="0" To="0.6" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="MouseOverHighlight"/>
              </Storyboard>
             </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="SelectionStates">
             <VisualStateGroup.Transitions>
              <VisualTransition GeneratedDuration="0:0:0.1"/>
             </VisualStateGroup.Transitions>
             <VisualState x:Name="Unselected"/>
             <VisualState x:Name="Selected">
              <Storyboard>
               <DoubleAnimation Duration="0" To="0.6" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectionHighlight"/>
              </Storyboard>
             </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="RevealStates">
             <VisualStateGroup.Transitions>
              <VisualTransition GeneratedDuration="0:0:0.5"/>
             </VisualStateGroup.Transitions>
             <VisualState x:Name="Shown">
              <Storyboard>
               <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
              </Storyboard>
             </VisualState>
             <VisualState x:Name="Hidden">
              <Storyboard>
               <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
              </Storyboard>
             </VisualState>
            </VisualStateGroup>
           </VisualStateManager.VisualStateGroups>
           <Grid Background="{TemplateBinding Background}">
             <TextBlock Text="{TemplateBinding FormattedDependentValue}" Canvas.ZIndex="100"/>
            <Rectangle>
             <Rectangle.Fill>
              <LinearGradientBrush>
               <GradientStop Color="#77ffffff" Offset="0"/>
               <GradientStop Color="#00ffffff" Offset="1"/>
              </LinearGradientBrush>
             </Rectangle.Fill>
            </Rectangle>
            <Border BorderBrush="#ccffffff" BorderThickness="1">
             <Border BorderBrush="#77ffffff" BorderThickness="1"/>
            </Border>
            <Rectangle x:Name="SelectionHighlight" Fill="Red" Opacity="0"/>
            <Rectangle x:Name="MouseOverHighlight" Fill="White" Opacity="0"/>
           </Grid>
          </Border>
         </ControlTemplate>
        </Setter.Value>
       </Setter>
      </Style>


    Mog Liang
    • 已标记为答案 Mog Liang 2010年10月1日 7:26
    2010年10月1日 7:07