C# 绘制图形-仅显示单个点

C# 绘制图形-仅显示单个点,c#,wpf,gnuplot,coordinate-systems,oxyplot,C#,Wpf,Gnuplot,Coordinate Systems,Oxyplot,(C#WPF申请) 我有一个问题,我必须“画”一个坐标系,只输入坐标(没有线条),如图所示 我想用一个图库,因为我还要画一个框架,我想用图库会很容易。 所以我发现了GnuPlot,Oxyplot,自己画。不幸的是,GnuPlot很愚蠢,因为它没有用于C#应用程序的库。(如果你有,请告诉我)。因此,我使用了OxyPlot,但不幸的是OxyPlot只显示坐标系。 现在回答我的问题。 有什么比用坐标画坐标系更好的方法吗? 应满足以下要求: 它应该是一个预览应用程序,也就是说,如果我改变大小,它应该

(C#WPF申请)

我有一个问题,我必须“画”一个坐标系,只输入坐标(没有线条),如图所示

我想用一个图库,因为我还要画一个框架,我想用图库会很容易。 所以我发现了GnuPlot,Oxyplot,自己画。不幸的是,GnuPlot很愚蠢,因为它没有用于C#应用程序的库。(如果你有,请告诉我)。因此,我使用了OxyPlot,但不幸的是OxyPlot只显示坐标系。 现在回答我的问题。 有什么比用坐标画坐标系更好的方法吗? 应满足以下要求:

  • 它应该是一个预览应用程序,也就是说,如果我改变大小,它应该直接发生
  • 我想做一个框架,所以它应该在这个过程中帮助我
  • 应该有一个图书馆
  • 它应该用于C#应用程序
  • 我想成为X,Y坐标的第一个点标记,但后来它应该是圆直径的圆
  • 稍后将显示为位图
如上所述,我将其与OxyPlot一起使用,但不幸的是,它没有绘制图形(我使用了示例文档)

也许你对OxyPlot有更好的想法/解决方案

提前谢谢,我很高兴收到你的每一个回复

XAML:

 <Window x:Class="TestOxyPlot.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:oxy="http://oxyplot.org/wpf"
            xmlns:local="clr-namespace:TestOxyPlot"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <oxy:Plot x:Name="oxyPlot" Title="{Binding Title}" Margin="207,53,0,0">
                <oxy:Plot.Series>
                    <oxy:LineSeries ItemsSource="{Binding Points}"/>
                </oxy:Plot.Series>
            </oxy:Plot>
            <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="44,64,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" MouseLeave="textBox_MouseLeave" TextChanged="textBox_TextChanged"/>
            <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="23" Margin="44,101,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="textBox1_TextChanged"/>
            <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="68,174,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
        </Grid>
    </Window>


使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用氧图;
命名空间TestOxyPlot
{
/// 
///Interaktionslogik für MainWindow.xaml
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
this.Title=“示例2”;
this.Points=新列表
{
新数据点(0,4),
新数据点(10,13),
新数据点(20,15),
新数据点(30,16),
新数据点(40,12),
新数据点(50、12)
};
}
公共字符串标题{get;private set;}
公共IList点{get;private set;}
private void textBox_MouseLeave(对象发送方,MouseEventArgs e)
{
}
私有void textBox\u TextChanged(对象发送者,textchangedventargs e)
{
尝试
{
oxyPlot.Width=Int32.Parse(textBox.Text);
}
捕获(异常错误)
{
MessageBox.Show(“消息:+错误”);
}
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
}
私有void textBox1_TextChanged(对象发送者,textchangedventargs e)
{
尝试
{
oxyPlot.Width=Int32.Parse(textBox.Text);
}
捕获(异常错误)
{
MessageBox.Show(“消息:+错误”);
}
}
}
}
添加此代码

 DataContext = this;
在这条线之后

 InitializeComponent();
它将显示图表。此外,要删除线并仅绘制标记,请使用类似于以下内容的
LineSeries

<oxy:LineSeries ItemsSource="{Binding Points}" LineStyle="None"  MarkerType="Circle" MarkerSize="5" MarkerFill="Black"/>

编辑

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        double randomNumX;
        double randomNumY;
        int h = DateTime.Now.Hour;
        int m = DateTime.Now.Minute;
        int s = DateTime.Now.Second;
        String u = h.ToString() + m.ToString() + s.ToString();
        int iu = Int32.Parse(u);
        Random zufall = new Random(iu);

        Points = new List<DataPoint>();
        for (int i = 0; i < 10; i++)
        {
            randomNumX = zufall.NextDouble() * (10 - -10) + -10;
            randomNumY = zufall.NextDouble() * (10 - -10) + -10;
            Points.Add(new DataPoint(randomNumX, randomNumY));
        }
        ls.ItemsSource = Points;
    }
private void按钮\u单击(对象发送者,路由目标)
{
双随机数;
双随机;
int h=DateTime.Now.Hour;
int m=DateTime.Now.Minute;
int s=DateTime.Now.Second;
字符串u=h.ToString()+m.ToString()+s.ToString();
intiu=Int32.Parse(u);
Random zufall=新随机(iu);
点=新列表();
对于(int i=0;i<10;i++)
{
randomNumX=zufall.NextDouble()*(10--10)+-10;
randomNumY=zufall.NextDouble()*(10--10)+-10;
添加(新数据点(randomNumX,randomNumY));
}
ls.ItemsSource=点;
}


顺便说一句,由于某种原因,使用ObservationCollection或InvalidatePlot(true)不起作用添加此代码

 DataContext = this;
在这条线之后

 InitializeComponent();
它将显示图表。此外,要删除线并仅绘制标记,请使用类似于以下内容的
LineSeries

<oxy:LineSeries ItemsSource="{Binding Points}" LineStyle="None"  MarkerType="Circle" MarkerSize="5" MarkerFill="Black"/>

编辑

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        double randomNumX;
        double randomNumY;
        int h = DateTime.Now.Hour;
        int m = DateTime.Now.Minute;
        int s = DateTime.Now.Second;
        String u = h.ToString() + m.ToString() + s.ToString();
        int iu = Int32.Parse(u);
        Random zufall = new Random(iu);

        Points = new List<DataPoint>();
        for (int i = 0; i < 10; i++)
        {
            randomNumX = zufall.NextDouble() * (10 - -10) + -10;
            randomNumY = zufall.NextDouble() * (10 - -10) + -10;
            Points.Add(new DataPoint(randomNumX, randomNumY));
        }
        ls.ItemsSource = Points;
    }
private void按钮\u单击(对象发送者,路由目标)
{
双随机数;
双随机;
int h=DateTime.Now.Hour;
int m=DateTime.Now.Minute;
int s=DateTime.Now.Second;
字符串u=h.ToString()+m.ToString()+s.ToString();
intiu=Int32.Parse(u);
Random zufall=新随机(iu);
点=新列表();
对于(int i=0;i<10;i++)
{
randomNumX=zufall.NextDouble()*(10--10)+-10;
randomNumY=zufall.NextDouble()*(10--10)+-10;
添加(新数据点(randomNumX,randomNumY));
}
ls.ItemsSource=点;
}