我想创建一个二维图并在该图上显示 2^40000 个点。现在显然不可能一次显示所有这些。没有人会简单地拥有这么多的记忆。所以,我想一次只显示某些点,比如 2^7 左右,并允许平移工具,所以当用户平移时,它会加载并显示下一个点。
所以,问题是:
1) 这在 WinForms 中可行吗?
2)当用户平移屏幕时如何获得通知。任何代码示例将不胜感激。
使用ZedGraph是可能的
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using ZedGraph;
namespace GraphTest
{
public partial class Form1 : Form
{
private readonly Fill _flip = new Fill(Color.White);
private readonly PointPairList _mPointsListSample;
private readonly GraphPane _myPane;
public Form1()
{
InitializeComponent();
_myPane = zedGraphControl1.GraphPane;
_myPane.YAxis.Title.Text = "Sample";
_myPane.YAxis.Title.FontSpec.Size = 5f;
_myPane.YAxis.Scale.FontSpec.Size = 5f;
_myPane.XAxis.Scale.FontSpec.Size = 5f;
_mPointsListSample = new PointPairList();
_myPane.Chart.Fill = new Fill(Color.White, Color.Black, 45F);
_myPane.Fill = new Fill(Color.White, Color.Black, 45F);
_myPane.XAxis.MajorGrid.IsVisible = true;
_myPane.XAxis.Scale.Min = 0;
_myPane.XAxis.Scale.Max = Convert.ToInt32(Math.Pow(2, 7));
_myPane.YAxis.Title.FontSpec.FontColor = Color.Pink;
_myPane.YAxis.Scale.Align = AlignP.Inside;
_myPane.YAxis.Scale.Min = 0;
_myPane.YAxis.Scale.Max = 500;
}
private void Form1_Shown(object sender, EventArgs e)
{
var limit = new Random();
bool flag = true;
while (true)
{
if (flag)
{
for (int i = 0; i < Convert.ToInt32(Math.Pow(2, 7)); i++)
{
_mPointsListSample.Add(i, limit.Next(500));
Thread.Sleep(50);
Application.DoEvents();
DrawGraph();
flag = false;
}
}
if (!flag)
{
for (int i = 0; i < Convert.ToInt32(Math.Pow(2, 7) - 1); i++)
_mPointsListSample[i].Y = _mPointsListSample[i + 1].Y;
_mPointsListSample.Insert(Convert.ToInt32(Math.Pow(2, 7) - 1), Convert.ToInt32(Math.Pow(2, 7) - 1), limit.Next(500));
_mPointsListSample.RemoveAt(Convert.ToInt32(Math.Pow(2, 7)));
Thread.Sleep(50);
Application.DoEvents();
DrawGraph();
}
}
}
private void DrawGraph()
{
_myPane.CurveList.Clear();
// Fabricate some data values
LineItem myCurve = _myPane.AddCurve("Sample", _mPointsListSample, Color.Red, SymbolType.Circle);
myCurve.Symbol.Fill = _flip;
myCurve.Line.IsVisible=false;
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
}
}
}
我希望它可能有助于使用 2D Graph 在 Winform 中绘制所有值,如您所期望的 2^7。