C# Plotting 라이브러리 OxyPlot
OxyPlot은 C#에서 사용할 수 있는 Plot 라이브러리로써 WPF/Windows Forms/Phone/Mono 등의 다양한 환경을 지원합니다.
OxyPlot
; https://github.com/oxyplot/oxyplot
Nuget을 통해 설치하는 것도 쉬운데요, 다음은 Windows Forms 용 설치 명령어입니다.
Install-Package OxyPlot.WindowsForms -Pre
설치 후 다음의 글에 따라 비주얼 스튜디오 도구상자에 컨트롤을 추가할 수 있습니다.
OxyPlot 라이브러리의 컨트롤을 Toolbox에 등록 시 오류
; https://www.sysnet.pe.kr/2/0/10970
그럼 디자인 화면에서 PlotView 컨트롤을 쉽게 Form 화면에 끌어다 놓을 수 있고 다음과 같이 코딩을 해주면,
using System;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
PlotModel _pm = new PlotModel();
public Form1()
{
InitializeComponent();
}
void InitializePlotView(PlotModel pm)
{
var axesX = new LinearAxis();
axesX.Position = AxisPosition.Bottom;
axesX.AxislineStyle = LineStyle.Solid;
axesX.PositionAtZeroCrossing = true;
axesX.Maximum = 50;
axesX.Minimum = -10;
axesX.MajorGridlineStyle = LineStyle.Dash;
axesX.MinorGridlineStyle = LineStyle.Dot;
var axesY = new LinearAxis();
axesY.Position = AxisPosition.Left;
axesY.AxislineStyle = LineStyle.Solid;
axesY.PositionAtZeroCrossing = true;
axesY.Maximum = 50;
axesY.Minimum = -10;
axesY.MajorGridlineStyle = LineStyle.Dash;
axesY.MinorGridlineStyle = LineStyle.Dot;
pm.Axes.Add(axesX);
pm.Axes.Add(axesY);
plotView.Model = pm;
}
private void Form1_Load(object sender, EventArgs e)
{
InitializePlotView(_pm);
ScatterSeries series = new ScatterSeries();
series.Points.Add(new ScatterPoint(10, 20));
series.Points.Add(new ScatterPoint(20, 30));
series.Points.Add(new ScatterPoint(30, 40));
series.MarkerType = MarkerType.Circle;
_pm.Series.Add(series);
}
}
}
이런 화면을 볼 수 있습니다.
(
첨부 파일은 이 글의 예제 코드를 포함합니다.)
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]