Silverlight 将StackedBarSeries和BarSeries分组在同一轴上

Silverlight 将StackedBarSeries和BarSeries分组在同一轴上,silverlight,silverlight-4.0,charts,silverlight-toolkit,stackedbarseries,Silverlight,Silverlight 4.0,Charts,Silverlight Toolkit,Stackedbarseries,我想在Silverlight toolkit水平条形图上显示3个系列…2个普通条形图系列和1个堆叠条形图系列(由2个系列定义组成)。当我添加前两个普通条序列时,它们会像预期的那样彼此相邻。但当我添加堆叠系列时,它占据了整行的高度。有没有办法将这两种类型的系列组合起来,使其显示为从上到下堆叠的条形图 以下是我目前的设置方式: <charts:Chart Title="Manufacturer Overview" LegendTitle="Legend" Style="{StaticResou

我想在Silverlight toolkit水平条形图上显示3个系列…2个普通条形图系列和1个堆叠条形图系列(由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个系列的“背面”:


因此,经过一系列的观察,我得出结论,这种行为是“设计”或bug造成的。我查看了
StackedBarSeries
的源代码。我创建了一个新类,该类继承自
StackedBarSeries
,并将代码添加到“UpdateDaiTemplacement”方法中,该方法将条的高度除以序列中的序列数:

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;
       }
   }
}
protectedoverride void updatedaiTemplacement(IEnumerable数据项)
{
/*工具箱中的一组代码*/
双倍总和=100?
group.DataItems.Sum(di=>Math.Abs(ValueHelper.ToDouble(di.DataPoint.ActualDependentValue)):
1.
如果(0==总和)
{
总和=1;
}
//我的补充
var numSeries=this.seriehost.Series.Count;
int index=this.seriehost.Series.IndexOf(this);
//末端添加
双上限=0;
双层地板=0;
foreach(组中的DataItem DataItem.DataItems)
{
DataPoint DataPoint=dataItem.DataPoint;
double value=IsStacked100?(ValueHelper.ToDouble(dataPoint.ActualDependentValue)*(100/和)):ValueHelper.ToDouble(dataPoint.ActualDependentValue);
if(ValueHelper.CanGraph(值))
{
双值坐标=实际独立轴。GetPlotArea坐标(值)。值;
双圆角坐标=(0