通过阅读代码,我可以在方法中看到
,有以下代码行:
double segmentWidth = coordinateRangeWidth * 0.8;
所以这是一个非常明确的“否”,您不能通过设置公共属性来改变列之间的间距。
我要尝试的解决方案是编写一个继承自
柱形图
,和重写
更新的数据点
.
好的,我去工作了。如果有人感兴趣,我已经附上historogramseries类的完整代码。
public class HistogramSeries : ColumnSeries, ISeries
{
protected override void UpdateDataPoint(DataPoint dataPoint)
{
// That set the height and width.
base.UpdateDataPoint(dataPoint);
// Now we override the part about setting the width
object category = dataPoint.ActualIndependentValue;
var coordinateRange = GetCategoryRange(category);
double minimum = (double)coordinateRange.Minimum.Value;
double maximum = (double)coordinateRange.Maximum.Value;
double coordinateRangeWidth = (maximum - minimum);
const int WIDTH_MULTIPLIER = 1; // Harcoded to 0.8 in the parent. Could make this a dependency property
double segmentWidth = coordinateRangeWidth * WIDTH_MULTIPLIER;
var columnSeries = SeriesHost.Series.OfType<ColumnSeries>().Where(series => series.ActualIndependentAxis == ActualIndependentAxis);
int numberOfSeries = columnSeries.Count();
double columnWidth = segmentWidth / numberOfSeries;
int seriesIndex = columnSeries.IndexOf(this);
double offset = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1;
double dataPointX = minimum + offset;
double left = Math.Round(dataPointX);
double width = Math.Round(columnWidth);
Canvas.SetLeft(dataPoint, left);
dataPoint.Width = width;
}
#region ISeries Members
System.Collections.ObjectModel.ObservableCollection<object> ISeries.LegendItems
{
get { return base.LegendItems; }
}
#endregion
#region IRequireSeriesHost Members
ISeriesHost IRequireSeriesHost.SeriesHost
{
get { return base.SeriesHost;}
set { base.SeriesHost = value; }
}
#endregion
}
// Copied from the DataVisualization library
// (It was an internal class)
static class MyEnumerableFunctions
{
public static int IndexOf(this IEnumerable that, object value)
{
int index = 0;
foreach (object item in that)
{
if (object.ReferenceEquals(value, item) || value.Equals(item))
{
return index;
}
index++;
}
return -1;
}
}