2013-08-26 3 views
1

서비스 유형에 대한 차트를 만들어야합니다. 유형을 동적으로 추가 할 수 있으며 각 유형에 대해 적절한 색상 정의가 없습니다.Silverlight Toolkit; 원형 차트 일부 색상 피하기

우리는 Telerik Silverlight RadChart를 사용하고 있으므로 클라이언트가 트릭 요구 사항을 충족 할 때까지 모든 것이 잘되었습니다. 그리드에 두 가지 색상, 즉 빨강과 녹색을 표시하면 안됩니다.

빨강 및 녹색 팔레트를 모두 피하고 임의 색상으로 차트를 렌더링 할 수있는 방법이 있습니까?

+0

내가 같은 퉜다 시나리오의 유형에 따라 마침내 그들에게 색상을 지정하게 만들었고 ("원하지 않는"색상 목록이 계속 커지기 때문에) RadChart.PaletteBrushes를 통해 색상 목록을로드 했으므로 더 웅변적인 방법을 알고 싶습니다. –

+0

Toolkit 차트에서이 작업을 수행하는 방법을 알고 있습니다. Telerik과 함께 일한 적은 없기 때문에 도움이되지 않습니다. – vorrtex

+0

@vorrtex 질문 **에 대답 해 주시겠습니까 ** Toolkit ** 만 작동합니까? 적어도 같은 개념을 사용하려고 할 수 있습니다. – Custodio

답변

0

툴킷 차트의 솔루션은 C# 코드로 색상을 생성하고 파이 데이터 포인트 템플릿을 완전히 다시 작성하는 것입니다. 내가 Telerik 차트에 대해 동일한 접근 방식을 설명하는 기사를 발견했다 그런데 은 : Binding the Color of Series Items

그래서 당신이 2 색을 제거하려는 경우, 그냥 ChartItemModel.Color 속성에 다른 색상을 설정합니다. C# 코드는 다음과 같이 될 것입니다 :

public class ChartItemModel 
{ 
    public string Title { get; set; } 

    public double Value { get; set; } 

    public Brush Color { get; set; } 
} 

var chartItems = new [] 
{ 
    new ChartItem { Title = "Item1", Value = 25, Color = (Brush)Resources["BlueBrush"] }, 
    new ChartItem { Title = "Item2", Value = 75, Color = (Brush)Resources["YellowBrush"] } 
    // other items, the Color property of which doesn't have a red or green brush 
}; 
// binding 

그리고 PieDataPoint 템플릿에서 복사 한 내장과 브러시 (Fill="{Binding Color}")에 바인딩을 추가하여 변경 :

<charting:PieSeries.DataPointStyle> 
    <Style TargetType="charting:PieDataPoint"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="charting:PieDataPoint"> 
        <Grid x:Name="Root" Opacity="0"> 
         <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 Storyboard.TargetName="MouseOverHighlight" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0" /> 
            </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 Storyboard.TargetName="SelectionHighlight" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0" /> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="RevealStates"> 
           <VisualStateGroup.Transitions> 
            <VisualTransition GeneratedDuration="0:0:0.5" /> 
           </VisualStateGroup.Transitions> 
           <VisualState x:Name="Shown"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0" /> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Hidden"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0" /> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Path x:Name="Slice" Data="{TemplateBinding Geometry}" Fill="{Binding Color}" Stroke="{TemplateBinding BorderBrush}" StrokeMiterLimit="1"> 
          <ToolTipService.ToolTip> 
           <StackPanel> 
            <ContentControl Content="{TemplateBinding FormattedDependentValue}" /> 
            <ContentControl Content="{TemplateBinding FormattedRatio}" /> 
           </StackPanel> 
          </ToolTipService.ToolTip> 
         </Path> 
         <Path x:Name="SelectionHighlight" Data="{TemplateBinding GeometrySelection}" Fill="Red" StrokeMiterLimit="1" IsHitTestVisible="False" Opacity="0" /> 
         <Path x:Name="MouseOverHighlight" Data="{TemplateBinding GeometryHighlight}" Fill="White" StrokeMiterLimit="1" IsHitTestVisible="False" Opacity="0" /> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</charting:PieSeries.DataPointStyle>