0

Silverlight 툴킷 가로 막 대형 차트에 3 개의 시리즈를 표시하고 싶습니다. 2 개의 일반 막대 시리즈와 1 개의 스택 막대 시리즈 (2 SeriesDefinition으로 구성)를 표시하고 싶습니다. 처음 2 개의 일반 막대 시리즈를 추가하면 예상대로 서로 옆에 나타납니다. 그러나 쌓인 계열을 추가하면 전체 행의 높이가됩니다. 2 가지 유형의 시리즈를 결합하여 상단에서 하단으로 - 스택, 막대, 막대로 표시 할 수있는 방법이 있습니까? 여기그룹 StackedBarSeries 및 BarSeries를 같은 축에 두십시오.

내가 현재 그것을하고 있어요 방법입니다

여기
<charts:Chart Title="Manufacturer Overview" LegendTitle="Legend" Style="{StaticResource ZChartNoBackground}"> 
<charts:Chart.Series> 
    <charts:StackedBarSeries> 
     <charts:SeriesDefinition Title="Oppotunities" 
       ItemsSource="{Binding Path=TotalValueInFunnelByVendor}" 
       IndependentValueBinding="{Binding IndependentValue}" 
       DependentValueBinding="{Binding DependentValue}"> 
     </charts:SeriesDefinition> 
     <!--SAMPLE DATA UNTIL REAL DATA IS IN--> 
     <charts:SeriesDefinition Title="Flow Business" 
       ItemsSource="{Binding Path=TotalValueInFunnelByVendor}" 
       IndependentValueBinding="{Binding IndependentValue}" 
       DependentValueBinding="{Binding DependentValue}"> 
     </charts:SeriesDefinition> 
    </charts:StackedBarSeries> 
    <charts:BarSeries Title="Sales to date" 
       ItemsSource="{Binding Path=SalesToDateByVendor}" 
       IndependentValueBinding="{Binding IndependentValue}" 
       DependentValueBinding="{Binding DependentValue}"> 
    </charts:BarSeries> 
    <charts:BarSeries Title="Forecasted" 
       ItemsSource="{Binding Path=ForecastedSalesByVendor}" 
       IndependentValueBinding="{Binding IndependentValue}" 
       DependentValueBinding="{Binding DependentValue}"> 
    </charts:BarSeries> 
</charts:Chart.Series> 
</charts:Chart> 

차트의 이미지입니다. 주의 초록색과 빨간색 막대가 올바르게 배치하지만 누적 가로 막 대형은 행의 높이와 "다시"다른 2 시리즈에 있습니다 :

Chart snapshot

답변

0

그래서 둘러보고 왕창 후, I 이 동작이 "설계 상"이거나 버그라는 결론에 도달했습니다. StackedBarSeries의 소스 코드를 살펴 보았습니다.

protected override void UpdateDataItemPlacement(IEnumerable<DefinitionSeries.DataItem> dataItems) 
{ 
    /* A BUNCH OF CODE FROM TOOLKIT */ 

    double sum = IsStacked100 ? 
     group.DataItems.Sum(di =>Math.Abs(ValueHelper.ToDouble(di.DataPoint.ActualDependentValue))) : 
     1; 
    if (0 == sum) 
    { 
     sum = 1; 
    } 

    // MY ADDITION   
    var numSeries = this.SeriesHost.Series.Count; 
    int index = this.SeriesHost.Series.IndexOf(this); 
    // END ADDITION 

    double ceiling = 0; 
    double floor = 0; 
    foreach (DataItem dataItem in group.DataItems) 
    { 
     DataPoint dataPoint = dataItem.DataPoint; 
     double value = IsStacked100 ? (ValueHelper.ToDouble(dataPoint.ActualDependentValue) * (100/sum)) : ValueHelper.ToDouble(dataPoint.ActualDependentValue); 
     if (ValueHelper.CanGraph(value)) 
     { 
      double valueCoordinate = ActualDependentAxis.GetPlotAreaCoordinate(value).Value; 
      double fillerCoordinate = (0 <= value) ? ceiling : floor; 

      double topCoordinate = 0, leftCoordinate = 0, height = 0, width = 0, deltaCoordinate = 0; 
      if (AxisOrientation.Y == ActualDependentAxis.Orientation) 
      { 
       topCoordinate = plotAreaMaximumDependentCoordinate - Math.Max(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate); 
       double bottomCoordinate = plotAreaMaximumDependentCoordinate - Math.Min(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate); 
       deltaCoordinate = bottomCoordinate - topCoordinate; 
       height = (0 < deltaCoordinate) ? deltaCoordinate + 1 : 0; 
       leftCoordinate = categoryMinimumCoordinate; 
       width = categoryMaximumCoordinate - categoryMinimumCoordinate + 1; 

       // MY MODIFICATION 
       //adjusting the width and offset to allow multiple columns to render beside each other instead of overtop 
       width = width/numSeries; 
       leftCoordinate = leftCoordinate + (width * index); 
       // 
      } 
      else 
      { 
       leftCoordinate = Math.Min(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate); 
       double rightCoordinate = Math.Max(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate); 
       deltaCoordinate = rightCoordinate - leftCoordinate; 
       width = (0 < deltaCoordinate) ? deltaCoordinate + 1 : 0; 
       topCoordinate = categoryMinimumCoordinate; 
       height = categoryMaximumCoordinate - categoryMinimumCoordinate + 1; 

       //MY MODIFICATION 
       //adjusting the height and offset to allow multiple columns to render beside each other instead of overtop 
       height = height/numSeries; 
       topCoordinate = topCoordinate + (height * index); 
       // 
      } 

      // THE REST OF THE CODE FROM THE TOOLKIT 
     } 
     else 
     { 
      dataPoint.Visibility = Visibility.Collapsed; 
     } 
    } 
} 
+0

좋군요 코드 : 나는 StackedBarSeries에서 상속과 SeriesHost 시리즈의 숫자로 바의 높이를 나누는 "UpdateDataItemPlacement"메서드에 코드를 추가하는 새로운 클래스를 생성 – saranya