2017-03-17 1 views
0

This is my current statusMontrez-moi l'axe des x et l'axe y dans OxyPlot

Dans l'image que vous voyez deux tons jaunes et deux couleurs plus vives reds.The sont les lignes créées avec le code. Les couleurs plus foncées ont été peintes avec de la peinture. J'adorerais montrer les Achs moyens. Je le fais déjà, mais pas autant que je le ferais. Dans l'image, vous pouvez voir que les axes ne vont pas complètement vers le bord. J'ai donc développé avec Paint it. Donc, il devrait regarder ensuite aussi après. Je voudrais demander à la fin quelle est la fourchette de valeur. (End signifie que les rectangles sont créés). Je pense que ce n'est pas la meilleure façon de créer les axes moyens. Je pense que c'est mieux, mais je ne sais pas comment. Comment est-ce que je peux faire que j'obtiens les courses tout le chemin au bord ou il y a une possibilité avec Par exemple plotModel.PlotType = showMiddleAxis? Et si je ne l'enregistre pas comme une image de l'Oxyplot mais comme un OxyPlot interactif, les axes devraient aussi être "aller".


EDIT:

Si j'ajoute les axes médians par code, le OxyPlot (que l'on voit l'ensemble des axes du milieu). Cela ne devrait pas être ainsi. Il devrait seulement zoomer sur les rectangles et les points.


J'espère que vous pouvez m'aider, merci.

Comme toujours, le code attend maintenant:

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> 

Si quelque chose devait manquer ou les ambiguïtés, laisser un commentaire là.

+0

Est-ce que vous [gabelundmesser] (http://stackoverflow.com/users/7597016/gabelundmesser)? – lokusking

+0

Non, je ne suis pas cet utilisateur. –

Répondre

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, });