我想在我的Silverlight工具包水平条形图上显示3个系列...2个普通条形图系列和1个堆叠条形图系列(由2个SeriesDefinition组成)。当我添加前两个正常的bar系列时,它们会像预期的那样显示在彼此的旁边。但是当我添加堆叠的序列时,它占据了整个行的高度。有没有办法组合这两种类型的序列,使其从上到下显示为-堆叠,条形,条形?
下面是我目前设置它的方法:
<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>这是图表的图像。请注意,绿色和红色的条形已正确放置,但堆叠的条形是行的高度,并且位于其他两个系列的“背面”:

发布于 2012-09-06 02:15:59
因此,在环顾四周一大堆之后,我得出的结论是,这种行为是“设计出来的”,或者是一个bug。我看了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;
}
}
}https://stackoverflow.com/questions/12269315
复制相似问题