[英]oxyplot - Y axis on both sides of chart
I am using the oxyplot lib to create timeseries Charts.我正在使用 oxyplot lib 创建时间序列图表。 I am trying to create a plot which has the same y-axis on both sides, it works fine as long as I am not interacting with the plot to zoom or pan, here is my code我正在尝试创建一个两侧具有相同 y 轴的图,只要我不与图进行交互以进行缩放或平移,它就可以正常工作,这是我的代码
model.Axes.Add(new LinearAxis()
{
MajorStep = 0.1,
Minimum = 0,
Maximum = 1,
Position = AxisPosition.Left,
Title = "Title Axis",
AxisTitleDistance = 10
});
model.Axes.Add(new LinearAxis()
{
Key = "RightYAxis"
MajorStep = 0.1,
Minimum = 0,
Maximum = 1,
Position = AxisPosition.Right
});
DateTimeAxis dta = new DateTimeAxis()
{
Key = "DateTimeAxis",
IntervalType = SetDateTimeIntervalType(minDate, maxDate),
StringFormat = "dd/MM/yyyy",
Position = AxisPosition.Bottom,
Minimum = DateTimeAxis.ToDouble(minDate),
Maximum = DateTimeAxis.ToDouble(maxDate),
Title = "Date",
AxisTitleDistance = 10
};
dta.AxisChanged += new EventHandler<AxisChangedEventArgs>(AxisChanged);
model.Axes.Add(dta);
When I interact with the plot, only the left y axis and the bottom axis are scaling appropriately.当我与绘图交互时,只有左侧 y 轴和底部轴适当缩放。 When I add the right y axis before the left y axis, the bottom and right side axis are scaling.当我在左侧 y 轴之前添加右侧 y 轴时,底部和右侧轴正在缩放。
What setting do I need to set, to scale both y axis accordingly and not just one?我需要设置什么设置才能相应地缩放两个 y 轴,而不仅仅是一个?
I don't think that there is a build-in setting for this.我不认为有一个内置的设置。 I had similar problem in the past and also looked for such a feature but didn't find one.我过去遇到过类似的问题,也寻找过这样的功能,但没有找到。 Also there is no such example in the OxyPlot demo browser.在 OxyPlot 演示浏览器中也没有这样的例子。 The straight forward - yet not very elegant way - is to attach an event handler also to the left axis which sets the minimum and maximum to the right one.直接 - 但不是很优雅的方式 - 是将一个事件处理程序也附加到左轴,将最小值和最大值设置为右轴。 Your example would then look like this:您的示例将如下所示:
Axis leftAxis = new LinearAxis()
{
MajorStep = 0.1,
Minimum = 0,
Maximum = 1,
Position = AxisPosition.Left,
Title = "Title Axis",
AxisTitleDistance = 10
});
leftAxis.AxisChanged += LeftAxis_AxisChanged;
model.Axes.Add(leftAxis);
model.Axes.Add(new LinearAxis()
{
Key = "RightYAxis"
MajorStep = 0.1,
Minimum = 0,
Maximum = 1,
Position = AxisPosition.Right
});
DateTimeAxis dta = new DateTimeAxis()
{
Key = "DateTimeAxis",
IntervalType = SetDateTimeIntervalType(minDate, maxDate),
StringFormat = "dd/MM/yyyy",
Position = AxisPosition.Bottom,
Minimum = DateTimeAxis.ToDouble(minDate),
Maximum = DateTimeAxis.ToDouble(maxDate),
Title = "Date",
AxisTitleDistance = 10
};
dta.AxisChanged += new EventHandler<AxisChangedEventArgs>(AxisChanged);
model.Axes.Add(dta);
with the event handler looking like事件处理程序看起来像
private void LeftAxis_AxisChanged(object sender, AxisChangedEventArgs e)
{
Axis leftAxis = sender as Axis;
Axis rightAxis = leftAxis.PlotModel.Axes.First(a => a.Position == AxisPosition.Right);
rightAxis.Maximum = leftAxis.ActualMaximum;
rightAxis.Minimum = leftAxis.ActualMinimum;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.