2017-03-17 209 views
0

This is my current status告訴我x軸和y軸在OxyPlot

在圖片中,你看到兩個黃色爲主色調和兩個reds.The鮮豔的顏色則與代碼創建的行。顏色較深的顏色已塗上油漆。我很想展示中間的Achs。我已經這樣做了,但並不像我想的那樣多。在圖片中,您可以看到斧頭不會完全靠近邊緣。所以我擴展了Paint。所以它應該看起來也是事後。我想問最後的價值範圍有多大。 (End是在矩形創建之後)。我認爲這不是創建中間軸的最佳方式。我認爲它更好,但不知道如何。 如何使筆畫一直到邊緣或有可能與 例如plotModel.PlotType = showMiddleAxis?如果我不將它保存爲Oxyplot的圖像,但作爲交互OxyPlot,軸也應該「去」。


編輯:

如果我通過代碼添加的中軸線,該OxyPlot(即一個人看到整個中軸線)。這不應該如此。它應該只放大矩形和點。


我希望你能幫助我,謝謝。

與往常一樣,現在的代碼在等待着你:

Rootobject.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace Rechteck 
{ 
    internal class Rootobject 
    { 
     public Point[] Points { get; set; } 
     public Rectangle[] Rectangles { get; set; } 
    } 

    internal class Point 
    { 
     public double X { get; set; } 
     public double Y { get; set; } 
    } 

    internal class Rectangle 
    { 
     public double XMin { get; set; } 
     public double XMax { get; set; } 
     public double YMin { get; set; } 
     public double YMax { get; set; } 
    } 

} 

MainWindow.xaml.cs

using System; 
using System.Collections.Generic; 
using System.Windows; 
using OxyPlot; 

namespace Rechteck 
{ 
    /// <summary> 
    /// Interaktionslogik für MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window, IPreviewCreator 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      m_bWithAxis = true; 
      m_bWithFrame = true; 
      m_bWithGrid = true; 
      m_bWithCenterAxis = true; 
      try 
      { 
       PlotModel plotModel; 
       if (withFrame) 
       { 
        plotModel = new PlotModel { }; 
       } 
       else 
       { 
        plotModel = new PlotModel { PlotAreaBorderColor = OxyColors.Transparent }; 
       } 

       plotModel.PlotType = PlotType.Cartesian; 

       if (withAxis) 
       { 
        if (withGrid) 
        { 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, MinimumPadding = 0.1, MaximumPadding = 0.1, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }); 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, MinimumPadding = 0.1, MaximumPadding = 0.1, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }); 
        } 
        else 
        { 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, MinimumPadding = 0.1, MaximumPadding = 0.1 }); 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, MinimumPadding = 0.1, MaximumPadding = 0.1 }); 
        } 
       } 
       else 
       { 
        if (withGrid) 
        { 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, MinorTickSize = 0, TickStyle = OxyPlot.Axes.TickStyle.None, TextColor = OxyColors.Transparent, MinimumPadding = 0.1, MaximumPadding = 0.1, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }); 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, MinorTickSize = 0, TickStyle = OxyPlot.Axes.TickStyle.None, TextColor = OxyColors.Transparent, MinimumPadding = 0.1, MaximumPadding = 0.1, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot }); 
        } 
        else 
        { 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, MinorTickSize = 0, TickStyle = OxyPlot.Axes.TickStyle.None, TextColor = OxyColors.Transparent, MinimumPadding = 0.1, MaximumPadding = 0.1 }); 
         plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, MinorTickSize = 0, TickStyle = OxyPlot.Axes.TickStyle.None, TextColor = OxyColors.Transparent, MinimumPadding = 0.1, MaximumPadding = 0.1 }); 
        } 
       } 

        var series2 = new OxyPlot.Series.LineSeries 
        { 
         LineStyle = LineStyle.None, 
         MarkerType = MarkerType.Circle, 
         MarkerSize = 5, 
         MarkerFill = OxyColors.Transparent, 
         MarkerStroke = OxyColors.Black, 
         MarkerStrokeThickness = 1, 
        }; 

        series2.Points.Add(new DataPoint(8.0, 1.0)); 
        series2.Points.Add(new DataPoint(4.0, 8.0)); 
        series2.Points.Add(new DataPoint(8.0, 4.0)); 
        series2.Points.Add(new DataPoint(1.0, 8.0)); 
        series2.Points.Add(new DataPoint(10.0, 1.0)); 

        series2.Smooth = true; 
        plotModel.Series.Add(series2); 

       for (int i = 0; i < 3; i++) 
       { 
        var series1 = new OxyPlot.Series.LineSeries 
        { 
         LineStyle = LineStyle.Solid, 
         MarkerType = MarkerType.Circle, 
         MarkerSize = 1, 
         MarkerFill = OxyColors.Transparent, 
         MarkerStroke = OxyColors.Black, 
         MarkerStrokeThickness = 1, 
        }; 

        switch (i) 
        { 

         case 0: 
          series1.Points.Add(new DataPoint(1.0, 1.0)); 
          series1.Points.Add(new DataPoint(4.0, 1.0)); 
          series1.Points.Add(new DataPoint(4.0, 4.0)); 
          series1.Points.Add(new DataPoint(1.0, 4.0)); 
          series1.Points.Add(new DataPoint(1.0, 1.0)); 
          break; 
         case 2: 
          series1.Points.Add(new DataPoint(3.0, 3.0)); 
          series1.Points.Add(new DataPoint(12.0, 3.0)); 
          series1.Points.Add(new DataPoint(12.0, 12.0)); 
          series1.Points.Add(new DataPoint(3.0, 12.0)); 
          series1.Points.Add(new DataPoint(3.0, 3.0)); 
          break; 
        } 

        series1.Smooth = false; 
        plotModel.Series.Add(series1); 

        for (int s = 0; s < 2; s++) 
        { 
         if (s == 0) 
         { 
          var series3 = new OxyPlot.Series.LineSeries 
          { 
           LineStyle = LineStyle.Solid, 
           MarkerType = MarkerType.Circle, 
           MarkerSize = 1, 
           Color = OxyColors.Yellow, 
           MarkerFill = OxyColors.Transparent, 
           MarkerStroke = OxyColors.Black, 
           MarkerStrokeThickness = 1, 
          }; 
          series3.Points.Add(new DataPoint(0, -10)); 
          series3.Points.Add(new DataPoint(0, +10)); 
          series3.Smooth = false; 
          plotModel.Series.Add(series3); 
         } 
         else 
         { 
          var series4 = new OxyPlot.Series.LineSeries 
          { 
           LineStyle = LineStyle.Solid, 
           MarkerType = MarkerType.Circle, 
           MarkerSize = 1, 
           Color = OxyColors.Red, 
           MarkerFill = OxyColors.Transparent, 
           MarkerStroke = OxyColors.Black, 
           MarkerStrokeThickness = 1, 
          }; 
          series4.Points.Add(new DataPoint(-10, 0)); 
          series4.Points.Add(new DataPoint(+10, 0)); 
          series4.Smooth = false; 
          plotModel.Series.Add(series4); 
         } 
        } 
       } 
       try 
        { 
         this.Content = new OxyPlot.Wpf.PlotView { Model = plotModel, Width = 800, Height = 800 }; 
        } 
        catch (Exception) 
        { 

        } 
      } 
      catch (Exception) 
      { 
      } 

     } 


     private List<double> pointX = new List<double>(); 
     private List<double> pointY = new List<double>(); 
     private bool m_bWithAxis; 
     private bool m_bWithFrame; 
     private bool m_bWithGrid; 
     private bool m_bWithCenterAxis; 
     public int m_iMargin; 

     public bool withAxis 
     { 
      get { return m_bWithAxis; } 
      set { m_bWithAxis = value; } 
     } 

     public bool withFrame 
     { 
      get { return m_bWithFrame; } 
      set { m_bWithFrame = value; } 
     } 

     public bool withGrid 
     { 
      get { return m_bWithGrid; } 
      set { m_bWithGrid = value; } 
     } 

     public bool withCenterAxis 
     { 
      get { return m_bWithCenterAxis; } 
      set { m_bWithCenterAxis = value; } 

     } 

     public int margin 
     { 
      get { return m_iMargin; } 
      set { m_iMargin = value; } 
     } 

     public bool actualizePreview(out string errorMessage) 
     { 
      throw new NotImplementedException(); 
     } 

     public void addPoint(double pX, double pY) 
     { 
      throw new NotImplementedException(); 
     } 

     public void addRectangle(double pXmin, double pXMax, double pYMin, double pYMax) 
     { 
      throw new NotImplementedException(); 
     } 

     public void clear() 
     { 
      throw new NotImplementedException(); 
     } 

     public bool readJSONFile(out string errorMessage, string filename) 
     { 
      throw new NotImplementedException(); 
     } 

     public bool savePicture(out string errorMessage, out System.Drawing.Image preview, int pWidth, int pHeight) 
     { 
      throw new NotImplementedException(); 
     } 

    } 
} 

MainWindow.xaml

<Window x:Class="Rechteck.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:Rechteck" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="900" Width="900"> 
    <Grid> 

    </Grid> 
</Window> 

若發現有丟失或模糊之處,發表評論那裏。

+0

難道你是[gabelundmesser](http://stackoverflow.com/users/7597016/gabelundmesser)? – lokusking

+0

不,我不是這個用戶。 –

回答

0
plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, ExtraGridlines = new double[] { 0 }, ExtraGridlineThickness = 1, ExtraGridlineColor = OxyColors.Blue, }); 

plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, ExtraGridlines = new double[] { 0 }, ExtraGridlineThickness = 1, ExtraGridlineColor = OxyColors.Red, });