0

我想在我的 Silverlight 工具包水平条形图上显示 3 个系列...2 个普通条形系列和 1 个堆叠条形系列(由 2 个组成SeriesDefinition)。当我添加前 2 个普通条形系列时,它们按预期彼此相邻显示。但是当我添加堆叠系列时,它占据了整行的高度。有什么方法可以组合这两种类型的系列,使其从上到下显示为 - 堆叠、条形、条形?

这是我目前的设置方式:

<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 个系列的“后面”:

图表快照

4

1 回答 1

0

因此,经过一大堆环顾四周,我得出的结论是这种行为是“设计使然”或错误。我查看了StackedBarSeries. 我创建了一个新类,该类继承自StackedBarSeries“UpdateDataItemPlacement”方法并将代码添加到该方法中,该方法将条形的高度除以 SeriesHost 中的系列数:

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;
       }
   }
}
于 2012-09-05T18:15:59.253 回答