Oxyplot中具有共享轴的多个图

时间:2014-03-03 17:02:28

标签: c# oxyplot

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

    [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;
    }

1 个答案:

答案 0 :(得分:4)

将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”等。