WPF___Oxyplot

2020. 2. 17. 11:07WPF/코드

https://stac

oxyplot.pdf
1.89MB
WpfApp1.zip
9.98MB

<<oxyplot.pdf>>

koverflow.com/questions/32697963/wpf-plotting-a-cosine-function-when-radiobutton-is-clicked

 

      1. <<WpfApp1.zip>>
      2. WPF 프로젝트 만들기
      3. 프로젝트 -> NuGet 패키지 관리

 

      1. 찾아보기 클릭 -> oxyplot 검색
      2. 검색 항목중 OxyPlot.Wpf 선택 -> 설치

 

 

      1. 설치가 완료 - 참조 항목 확인

 

 

 

 

 

 

File Name : "MainWindow.xmal"

 

<Window x:Class="WpfApp1.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:WpfApp1"

xmlns:oxy="http://oxyplot.org/wpf"

mc:Ignorable="d"

Title="MainWindow" Height="410.333" Width="525">

<Window.DataContext>

<local:MainPlotView/>

</Window.DataContext>

<Grid>

<Grid Background="#FFE5E5E5">

<oxy:PlotView x:Name="MyPlot" Model="{Binding MyModel}" IsEnabled="False"/>

</Grid>

</Grid>

</Window>

 

File Name : "MainPlotView.cs"

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using OxyPlot;

using OxyPlot.Series;

using OxyPlot.Annotations;

using OxyPlot.WindowsForms;

using OxyPlot.Wpf;

using OxyPlot.Axes;

using System.Windows.Threading;

namespace WpfApp1

{

public class MainPlotView

{

public DispatcherTimer timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) };

 

public static double[] Plot_Y_Data = new double[160];

 

public MainPlotView()

{

//PlotView_Bar();

Plot_Init();

Plot_Update();

}

 

private void Plot_Init ()

{

this.MyModel = new PlotModel()

{

Title = "DSP",

};

}

 

private void Plot_Update( )

{

Random rnd = new Random();

var data = new DataPoint[160];

MainWindow mw = new MainWindow();

 

timer.Tick += (sender, args) =>

{

//var buf = mw.Plot_Y_Data;

MyModel.Series.Clear();

 

for (int i = 0; i < 160; i++)

{

data[i] = new DataPoint(i, Plot_Y_Data[i]);

}

 

var stemseries = new StemSeries();

stemseries.Points.AddRange(data);

MyModel.Series.Add(stemseries);

MyModel.InvalidatePlot(true);

};

 

timer.Start();

}

 

private void PlotView_Bar()

{

Random rnd = new Random();

BarPoints = new List<DataPoint>();

DispatcherTimer timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };

this.Title = "DSP";

 

timer.Tick += (sender, args) =>

{

BarPoints.Clear();

 

for (int i = 0; i < 160; i++)

{

BarPoints.Add(new DataPoint(i, rnd.Next()));

}

};

timer.Start();

}

 

public PlotModel MyModel { get; private set; }

public string Title { get; private set; }

public IList<DataPoint> Points { get; private set; }

public IList<DataPoint> BarPoints { get; private set; }

}

}