WPF-라디오 버튼을 클릭 할 때 코사인 함수 플로팅

GaoGaiGar

방금 C #을 배우기 시작했고 사용자가 WPF GUI 인터페이스를 사용하여 라디오 버튼을 누를 때 코사인을 플로팅하고 싶습니다. 다른 클래스에서 호출 객체를 사용하는 방법에 문제가 있다고 생각합니다. 미리 감사드립니다. 아래는 내 코드입니다.

namespace WpfApplication2
{
    using OxyPlot;
    using OxyPlot.Annotations;
    using OxyPlot.Axes;
    using OxyPlot.Series;

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }



        private void button_Click_2(object sender, RoutedEventArgs e)
        {
            if (radioButton1.IsChecked == true)
            {
                MessageBox.Show("Plot Cosine");
                //I think solution should be something like this
                //MainViewModel.MyModel.Series.Add(new FunctionSeries(Math.Cos, -10, 10, 0.01, "cos(x)"));

            }
        }

    }

    public class MainViewModel : Window
    {
        //Plotting without any user input
        public const double Pi = 3.14159265358979323846;
        public const int SpeedOfLight = 3 * 10 ^ 8; // m per sec.


        //OxyPlot.Wpf.PlotModel plot = new OxyPlot.Wpf.PlotView();

        public MainViewModel()
        {
            MyModel = new PlotModel { Title = "Your Equation", LegendTitle = "Equations" };
            MyModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Distance" });
            MyModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Height" });


            //Determine your range for the plot
            //MyModel.Axes.Add(new LinearAxis(AxisPosition.Bottom, -10, 10));
            //MyModel.Axes.Add(new LinearAxis(AxisPosition.Left, -5, 5));


            MyModel.Series.Add(new FunctionSeries(Math.Cos, -10, 10, 0.01, "cos(x)"));
            MyModel.Series.Add(new FunctionSeries(Math.Sin, -10, 10, 0.01, "sin(x)"));

            LineSeries linePoints = new LineSeries() { };
            double x, y;
            DataPoint XYpoint = new DataPoint();
            for (x = -10; x <= 10; x += 0.01)
            {
                //Make sure not 1/3 since C# will read it as integer divided by integer hence 1/3=0
                //Use Math.Pow for powers
                //Definately Matlab is easier to plot stuff XD
                y = 1.0 / 2.0 * Math.Pow(x, 2) + 1;
                XYpoint = new DataPoint(x, y);
                linePoints.Points.Add(XYpoint);

            }

            MyModel.Series.Add(linePoints);
            MyModel.InvalidatePlot(true);

        }


        public PlotModel MyModel { get; private set; }

    }

}

다음은 XAML 코드입니다.

<Window x:Name="plot" x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:oxy="http://oxyplot.org/wpf"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
        Title="Plots" Height="450.307" Width="955.532" Background="White">
    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="73*"/>
            <RowDefinition Height="11*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="145*"/>
            <ColumnDefinition Width="329*"/>
        </Grid.ColumnDefinitions>


        <oxy:PlotView Title="{Binding Title}" Margin="4,0,0,0" Model="{Binding MyModel}" Grid.Column="1" >
            <oxy:PlotView.Series>
                <oxy:LineSeries ItemsSource="{Binding Points}"/>
            </oxy:PlotView.Series>
        </oxy:PlotView>
        <Label x:Name="label"  HorizontalAlignment="Left" Height="30" Margin="120,185,0,0" VerticalAlignment="Top" Width="142"/>

        <RadioButton x:Name="radioButton1" Content="Plot Cosine" Grid.Column="1" HorizontalAlignment="Left" Height="20" Margin="50,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="85" />

        <Button x:Name="button1" Content="Clear" HorizontalAlignment="Left" Height="35" Margin="120,7,0,0" Grid.Row="1" VerticalAlignment="Top" Width="142" Click="button_Click_2"/>
    </Grid>
</Window>
Ugur

씨#

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Axes;

namespace WpfApplication2
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public PlotModel MyModel { get; private set; }


        public MainWindow()
        {
            InitializeComponent();

            MyModel = new PlotModel { Title = "Your Equation", LegendTitle = "Equations" };
            MyModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Distance" });
            MyModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Height" });
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (radioButton1.IsChecked == true)
            {
                //MessageBox.Show("Plot Cosine");
                graph();

            }
        }


        public double getValue(int x, int y)
        {
            return (10 * x * x + 11 * x * y * y + 12 * x * y);
        }

        //setting the values to the function
        public FunctionSeries GetFunction()
        {
            int n = 100;
            FunctionSeries serie = new FunctionSeries();
            for (int x = 0; x < n; x++)
            {
                for (int y = 0; y < n; y++)
                {
                    //adding the points based x,y
                    DataPoint data = new DataPoint(x, getValue(x, y));

                    //adding the point to the serie
                    serie.Points.Add(data);
                }
            }
            //returning the serie
            return serie;
        }


        public void graph()
        {
            MyModel = new PlotModel { Title = "example" };
            MyModel.LegendPosition = LegendPosition.RightBottom;
            MyModel.LegendPlacement = LegendPlacement.Outside;
            MyModel.LegendOrientation = LegendOrientation.Horizontal;

            MyModel.Series.Add(GetFunction());
            var Yaxis = new OxyPlot.Axes.LinearAxis();
            OxyPlot.Axes.LinearAxis XAxis = new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, Minimum = 0, Maximum = 100 };
            XAxis.Title = "X";
            Yaxis.Title = "10 * x * x + 11 * x*y*y  + 12*x*y";
            MyModel.Axes.Add(Yaxis);
            MyModel.Axes.Add(XAxis);
            this.plot.Model = MyModel;
        }










    }
}

XAML

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:oxy="http://oxyplot.org/wpf"
        xmlns:local="clr-namespace:WpfApplication2"
        Title="MainWindow" Height="350" Width="525">




    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="73*"/>
            <RowDefinition Height="11*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="145*"/>
            <ColumnDefinition Width="329*"/>
        </Grid.ColumnDefinitions>


        <oxy:PlotView  Margin="4,0,0,0"  Grid.Column="1" Name="plot" >
            <!--<oxy:PlotView.Series>
                <oxy:LineSeries ItemsSource="{Binding Points}"/>
            </oxy:PlotView.Series>-->
        </oxy:PlotView>
        <Label x:Name="label"  HorizontalAlignment="Left" Height="30" Margin="120,185,0,0" VerticalAlignment="Top" Width="142"/>

        <RadioButton x:Name="radioButton1" IsChecked="True" Content="Plot Cosine" Grid.Column="1" HorizontalAlignment="Left" Height="20" Margin="50,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="85"  />

        <Button x:Name="button1" Content="Clear" HorizontalAlignment="Left" Height="35" Margin="120,7,0,0" Grid.Row="1" VerticalAlignment="Top" Width="142" Click="button1_Click"/>
    </Grid>
</Window>

여기에 이미지 설명 입력

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

라디오 버튼을 클릭 할 때 변수 값 변경

분류에서Dev

라디오 버튼을 클릭 할 때 Struts 작업으로 리디렉션

분류에서Dev

JQuery : 라디오 버튼을 클릭 할 때 HTML로 값을 어떻게 인쇄합니까?

분류에서Dev

클릭 할 때 data-toggle = tab으로 라디오 버튼을 확인하지 않았습니다.

분류에서Dev

라디오 버튼의 레이블을 클릭 할 수있을 때 두 번 클릭

분류에서Dev

새 라디오 버튼을 클릭 할 때 Matplotlib 서브 플롯 캔버스 그림을 지우는 방법 PySimpleGUI?

분류에서Dev

사용자가 라디오 버튼을 확인할 때 라디오 버튼이 자동으로 확인 됨

분류에서Dev

로그인 버튼을 클릭 할 때 페이지를 찾을 수 없음 404

분류에서Dev

라디오 버튼과 버튼을 함께 사용할 때 Python 프로그램이 중단됨

분류에서Dev

라디오 버튼과 버튼을 함께 사용할 때 Python 프로그램이 중단됨

분류에서Dev

WebDriver : '라디오 버튼'을 클릭 할 수 없음

분류에서Dev

reactjs에서 버튼을 클릭 할 때 함수를로드하는 방법

분류에서Dev

버튼을 클릭 할 때마다 라디오가 확인되지 않는 이유

분류에서Dev

라디오 버튼을 클릭 할 때 사용자 세부 정보를 필터링 하시겠습니까?

분류에서Dev

ReactJS-라디오 버튼을 클릭 할 때 동적으로 컴포넌트 색상 변경

분류에서Dev

양식을 제출하고 다른 파일로 정보를 보내기를 클릭 할 때 라디오 버튼

분류에서Dev

라디오 버튼은 더블 클릭 할 때만 값을 변경합니까?

분류에서Dev

Django : 버튼을 클릭 할 때 Python 함수 호출

분류에서Dev

Tkinter : 버튼을 클릭했을 때 버튼의 텍스트를 함수에 인자로 전달하는 방법

분류에서Dev

뒤로 버튼을 눌렀을 때 라디오 버튼을 어떻게 선택 해제 할 수 있습니까?

분류에서Dev

제출 버튼을 클릭 할 때 호출 할 수있는 함수를 jsp로 작성하는 방법

분류에서Dev

라디오 버튼을 사용할 때 널 포인터 예외

분류에서Dev

Python-버튼을 클릭 할 때 호출되는 함수 내에서 변수 값을 사용하는 방법

분류에서Dev

WPF Caliburn.Micro에서 버튼을 클릭 할 때 DataGrid에서 모두 선택할 수 없습니다.

분류에서Dev

Google+ 로그인 버튼을 클릭 할 수 없음

분류에서Dev

ng-repeat에서 라디오 버튼을 클릭 할 수 없습니다.

분류에서Dev

Selenium Webdriver에서 라디오 버튼을 클릭 할 수 없습니다.

분류에서Dev

제출 버튼을 클릭했을 때 라디오 버튼이 선택되었는지 확인하는 방법

분류에서Dev

div 오버레이로 인해 버튼을 클릭 할 수 없음-가능한 Z- 색인 문제

Related 관련 기사

  1. 1

    라디오 버튼을 클릭 할 때 변수 값 변경

  2. 2

    라디오 버튼을 클릭 할 때 Struts 작업으로 리디렉션

  3. 3

    JQuery : 라디오 버튼을 클릭 할 때 HTML로 값을 어떻게 인쇄합니까?

  4. 4

    클릭 할 때 data-toggle = tab으로 라디오 버튼을 확인하지 않았습니다.

  5. 5

    라디오 버튼의 레이블을 클릭 할 수있을 때 두 번 클릭

  6. 6

    새 라디오 버튼을 클릭 할 때 Matplotlib 서브 플롯 캔버스 그림을 지우는 방법 PySimpleGUI?

  7. 7

    사용자가 라디오 버튼을 확인할 때 라디오 버튼이 자동으로 확인 됨

  8. 8

    로그인 버튼을 클릭 할 때 페이지를 찾을 수 없음 404

  9. 9

    라디오 버튼과 버튼을 함께 사용할 때 Python 프로그램이 중단됨

  10. 10

    라디오 버튼과 버튼을 함께 사용할 때 Python 프로그램이 중단됨

  11. 11

    WebDriver : '라디오 버튼'을 클릭 할 수 없음

  12. 12

    reactjs에서 버튼을 클릭 할 때 함수를로드하는 방법

  13. 13

    버튼을 클릭 할 때마다 라디오가 확인되지 않는 이유

  14. 14

    라디오 버튼을 클릭 할 때 사용자 세부 정보를 필터링 하시겠습니까?

  15. 15

    ReactJS-라디오 버튼을 클릭 할 때 동적으로 컴포넌트 색상 변경

  16. 16

    양식을 제출하고 다른 파일로 정보를 보내기를 클릭 할 때 라디오 버튼

  17. 17

    라디오 버튼은 더블 클릭 할 때만 값을 변경합니까?

  18. 18

    Django : 버튼을 클릭 할 때 Python 함수 호출

  19. 19

    Tkinter : 버튼을 클릭했을 때 버튼의 텍스트를 함수에 인자로 전달하는 방법

  20. 20

    뒤로 버튼을 눌렀을 때 라디오 버튼을 어떻게 선택 해제 할 수 있습니까?

  21. 21

    제출 버튼을 클릭 할 때 호출 할 수있는 함수를 jsp로 작성하는 방법

  22. 22

    라디오 버튼을 사용할 때 널 포인터 예외

  23. 23

    Python-버튼을 클릭 할 때 호출되는 함수 내에서 변수 값을 사용하는 방법

  24. 24

    WPF Caliburn.Micro에서 버튼을 클릭 할 때 DataGrid에서 모두 선택할 수 없습니다.

  25. 25

    Google+ 로그인 버튼을 클릭 할 수 없음

  26. 26

    ng-repeat에서 라디오 버튼을 클릭 할 수 없습니다.

  27. 27

    Selenium Webdriver에서 라디오 버튼을 클릭 할 수 없습니다.

  28. 28

    제출 버튼을 클릭했을 때 라디오 버튼이 선택되었는지 확인하는 방법

  29. 29

    div 오버레이로 인해 버튼을 클릭 할 수 없음-가능한 Z- 색인 문제

뜨겁다태그

보관