在下在使用OXYPlot画LinearBarSeries条形图时想让所有条形图上方一直显示对应的数据,下面是对应绘图的代码
DisplayModel = new PlotModel() { Title = "数据统计表", TitleFontSize = 10, TitleClippingLength = 10, AxisTierDistance = 4.0, AssignColorsToInvisibleSeries = false, };
// 添加图例说明
DisplayModel.Legends.Add(new Legend
{
LegendPlacement = LegendPlacement.Outside,
LegendPosition = LegendPosition.BottomCenter,
LegendOrientation = LegendOrientation.Horizontal,
LegendBorderThickness = 0,
LegendTextColor = OxyColors.LightGray,
});
///
/// 添加条形统计图到Chart
///
/// <param name="index"></param>
private void CreateBarPlot(int index)
{
string title = "";
//添加plotchart Y轴
var ay1 = new LinearAxis()
{
Key = "y1",
Position = AxisPosition.Left,
};
//添加X轴
var ax = new DateTimeAxis()
{
Minimum = minValue,
Maximum = maxValue,
StringFormat = XAxisFormat,
FontSize = 14,
MajorStep = MinuteInterval / (24 * 60),//X轴时间间隔
Position = AxisPosition.Bottom,
Angle = 25,
IsZoomEnabled = false,
IsPanEnabled=true,
IntervalType = DateTimeIntervalType.Auto,//X轴时间间隔类型
IntervalLength = 1,
MinorIntervalType = DateTimeIntervalType.Auto,
};
var totalBarSeries = new LinearBarSeries();
totalBarSeries.YAxisKey = "y1";
totalBarSeries.BarWidth = 22;
//totalBarSeries.FillColor = OxyColor.FromArgb(69, 76, 175, 80);
//totalBarSeries.StrokeThickness = 1;
//totalBarSeries.StrokeColor = OxyColor.FromArgb(255, 76, 175, 80);
// 点击时弹出的label内容
totalBarSeries.TrackerFormatString = "{4:0}";
totalBarSeries.RenderInLegend = true;
// 设置数据绑定源和字段
totalBarSeries.ItemsSource = DataList;
totalBarSeries.DataFieldX = "Date";
totalBarSeries.DataFieldY = GetYValue(index, ref title);//根据index获取对应绑定数据与标题
totalBarSeries.Title=title;
DisplayModel.Series.Add(totalBarSeries);
DisplayModel.Axes.Add(ay1);
DisplayModel.Axes.Add(ax);
// 设置图形边框
DisplayModel.PlotAreaBorderThickness = new OxyThickness(1, 0, 1, 1);
}
上面图片是当前效果与在下想达到的需求