2016-01-31 152 views
1

我尝试学习使用oxyplot。当我在表单上显示一个图形时,该图形将覆盖所有表单区域(如下所示)。我想把它放在与尺寸有关的特定坐标上。设置OXYPLOT C的位置和大小#

我该怎么做?

我的代码:

private void Plot() 
{ 

    PlotView pv = new PlotView(); 
    pv.Dock = DockStyle.Fill; 
    this.Controls.Add(pv); 

    LinearAxis XAxis = new LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom }; 
    LinearAxis YAxis = new LinearAxis(); 
    PlotModel pm = new PlotModel(); 
    pm.Axes.Add(XAxis); 
    pm.Axes.Add(YAxis); 
    pm.Background = OxyColor.FromRgb(0, 0, 255); 
    pv.Model = pm; 
    pv.Model.Series.Add(GetFunction()); 
} 

private FunctionSeries GetFunction() 
    { 
     FunctionSeries fs = new FunctionSeries(); 
     for(int x=-10;x<=10;x++) 
      for(int y=-10;y<10;y++) 
      { 
       DataPoint data = new DataPoint(x, y); 
       fs.Points.Add(data); 
      } 
     return fs; 
    } 

结果:

enter image description here

回答

1

你应该创建XAML中PlotView,PlotView Model属性绑定到代码的PlotModel身后,然后,把它作为一个正常的框架元素:

<oxy:PlotView Model="{Binding pm}" Height="200" Width="200" 
       HorizontalAlignment="Right" Margin="20"/> 
+0

我找不到任何有关我的f的xaml文件ORM。它在哪里? – ffttyy

+0

对不起,我认为你使用WPF,但你是在窗体上。也许你可以在后面的代码中编辑视图的相同属性,就像你一直在做的那样。 – Jose

+0

@ffttyy,在这种情况下,只需在控制包中添加'pv'而不是主窗体。 –