5

我想使用 OXYPLOT 库添加多个共享 x 轴的图。示例代码如下,它设置了 4 个不同的 y 轴共享同一个 x 轴。但是我只能在第一个 x&y 轴上绘制数据,而不能在其他轴上绘制数据。任何形式的建议将不胜感激。

    [Example("Untitled")]
    public static PlotModel Untitled()
    {
        var plotModel1 = new PlotModel();
        plotModel1.PlotMargins = new OxyThickness(40,20,40,30);
        var linearAxis1 = new LinearAxis();
        linearAxis1.EndPosition = 0.25;
        linearAxis1.Maximum = 1;
        linearAxis1.Minimum = -1;
        linearAxis1.Title = "C1";
        linearAxis1.Key= "C1";
        plotModel1.Axes.Add(linearAxis1);
        var linearAxis2 = new LinearAxis();
        linearAxis2.EndPosition = 0.5;
        linearAxis2.Maximum = 1;
        linearAxis2.Minimum = -1;
        linearAxis2.Position = AxisPosition.Right;
        linearAxis2.StartPosition = 0.25;
        linearAxis2.Title = "C2";
        linearAxis2.Key= "C2";
        plotModel1.Axes.Add(linearAxis2);
        var linearAxis3 = new LinearAxis();
        linearAxis3.EndPosition = 0.75;
        linearAxis3.Maximum = 1;
        linearAxis3.Minimum = -1;
        linearAxis3.StartPosition = 0.5;
        linearAxis3.Title = "C3";
        linearAxis3.Key= "C3";
        plotModel1.Axes.Add(linearAxis3);
        var linearAxis4 = new LinearAxis();
        linearAxis4.Maximum = 1;
        linearAxis4.Minimum = -1;
        linearAxis4.Position = AxisPosition.Right;
        linearAxis4.StartPosition = 0.75;
        linearAxis4.Title = "C4";
        linearAxis1.Key= "C4";
        plotModel1.Axes.Add(linearAxis4);
        var linearAxis5 = new LinearAxis();
        linearAxis5.Maximum = 100;
        linearAxis5.Minimum = 0;
        linearAxis5.Position = AxisPosition.Bottom;
        linearAxis5.Title = "s";
        linearAxis5.Key= "s";
        plotModel1.Axes.Add(linearAxis5);
        return plotModel1;
    }
4

2 回答 2

7

将 XAxisKey 和 YAxisKey 属性分配给您的系列。

PlotModel pm = new PlotModel();

OxyPlot.Series.FunctionSeries s1 = new FunctionSeries(Math.Sin, -10, 10, 0.1, "sin(x)");
s1.YAxisKey = "axesY2";
s1.XAxisKey = "axesX2";
pm.Series.Add(s1);

在您的情况下,键是“C1”、“C2”和“C3”等。

于 2014-11-25T08:49:45.367 回答
0

如前所述,您必须将 YAxisKey 和 XAxisKey 属性与 StartPosition 和 EndPosition 结合使用。位置以百分比表示(从 0 到 1),因此例如,如果您想平分图形的 Y 轴,您可以尝试如下代码:

float percentage = 1f / NumberOfGraphs;
for (int i = 1; i <= NumberOfGraphs; i++) {
    ...
    LinearAxis yAxes = new LinearAxis();
    yAxes.Position = OxyPlot.Axes.AxisPosition.Left;
    yAxes.StartPosition = (i - 1) * percentage;
    yAxes.EndPosition = i * percentage;
    yAxes.Key = "Y" + i;
    ...
    LineSeries lineSerie = new LineSeries();
    lineSerie.YAxisKey = "Y" + i;
    ...
    yourPlotView.Model.Series.Add(lineSerie)
}
于 2021-09-17T09:35:37.403 回答