在OxyPlot中显示x轴和y轴

时间:2017-03-17 06:45:48

标签: c# wpf coordinates coordinate-systems oxyplot

This is my current status

在图片中,您会看到两个黄色色调和两个红色。较亮的颜色是使用代码创建的线条。深色的颜色涂上了油漆。我很想展示中间的阿克斯。我已经这样做了,但没有那么多。在图片中你可以看到轴没有完全走到边缘。所以我用Paint来扩展它。所以它之后也应该看起来。我想问最后价值范围有多大。 (结束意味着在创建矩形之后)。我认为这不是创建中轴的最佳方式。我认为它更好,但不知道如何。 我怎样才能让笔画一直到边缘或者有可能 例如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>

如果遗漏某些内容或含糊不清,请在那里留言。

1 个答案:

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