In the picture you see two yellow tones and two reds.The brighter colors are the lines created with the code. The darker colors have been painted with paint.I would love to show the Middle Achs. I already do this, but not as much as I would.In the picture you can see that the axes do not go completely to the edge. So I've expanded with Paint it. So it should look then also afterwards. I would like to ask in the end how big is the value range. (End is meant after the rectangles are created). I think it's not the best way to create the mid-axes. I think it's better, but do not know how.
How can I make that I get the strokes all the way to the edge or there is a possibility with
For example plotModel.PlotType = showMiddleAxis
? And if I do not save it as an image the Oxyplot but as an interactive OxyPlot the axes should also be "go".
EDIT:
If I add the middle axes by code, the OxyPlot (That one sees the whole middle axes). This should not be so. It should only zoom the rectangles and points.
I hope you can help me, thank you.
As always, the code now awaits you:
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>
If something should be missing or ambiguities, leave a comment there.
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, });