c#如何花很长的曲线图,求教。

azhou88 2019-08-01 04:11:58
数据很多,在winfrom 中如何话很长的曲线图,下面需要有滚动条,可以来回拖动。求教,
...全文
136 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
azhou88 2019-08-02
  • 打赏
  • 举报
回复
谢谢诸位了,各位说的我会注意印证,看看那个方法好用。谢谢,回头结分。分不多,结个缘分。
良朋 2019-08-02
  • 打赏
  • 举报
回复
CSDN好人多高手多。
github_36000833 2019-08-01
  • 打赏
  • 举报
回复
根据滚动条的位置,来确定显示那一段的数据。 比如下面的例子代码(微有改动),演示了300兆数据的图形化。 [quote 代码l引用自:] https://bbs.csdn.net/topics/390614100 13楼 C#大数据处理 [问题点数:100分,结帖人porenasckx [/quote]

    using System.IO;
    using System.IO.MemoryMappedFiles;

    public partial class Form1 : Form
    {
        public Form1()
        {
            //InitializeComponent();
            string filename = "example.dat";
            if (!File.Exists(filename))
            {
                MessageBox.Show("首次运行... 创建300M数据文件: " + filename);
                GenerateData(filename);
            }
            this.memoryMappedFile = MemoryMappedFile.CreateFromFile(filename);
            this.scrollbar = new HScrollBar()
            {
                Height = 32,
                Dock = DockStyle.Bottom,
                Maximum = (int)(new FileInfo(filename).Length / 4),
            };
            this.scrollbar.ValueChanged += (sender, e) => this.Invalidate(invalidateChildren: false);
            this.Controls.Add(scrollbar);
            this.DoubleBuffered = true;
            this.Size = new Size(800, 600);
        }
        ScrollBar scrollbar;
        MemoryMappedFile memoryMappedFile;

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            int sampling = 100;
            int start = Math.Min(this.scrollbar.Value, this.scrollbar.Maximum - sampling);
            e.Graphics.DrawCurve(Pens.Black, GetPoints(start, sampling));
            e.Graphics.DrawString(start.ToString("n0"), this.Font, Brushes.DarkBlue, new Point(200, 15));
        }

        private PointF[] GetPoints(int start, int count)
        {
            List<PointF> points = new List<PointF>(count);
            using (var viewStream = memoryMappedFile.CreateViewStream(start * sizeof(float), count * sizeof(float)))
            using (var reader = new BinaryReader(viewStream))
            {
                for (int i = 0; i < count; i++)
                {
                    float x = i * this.ClientRectangle.Width / 100;
                    float y = reader.ReadSingle() * this.ClientRectangle.Height;
                    points.Add(new PointF(x, y));
                }
            }
            return points.ToArray();
        }

        private void GenerateData(string outputFile, int count = 75 * 1024 * 1024)
        {
            Random random = new Random(123);
            using (BinaryWriter writer = new BinaryWriter(new FileStream(outputFile, FileMode.Create)))
            {
                float last = 0.5f;
                for (int i = 0; i < count; i++)
                {
                    last = last + (float)(random.NextDouble() - 0.5) / 20;
                    last = Math.Max(0, Math.Min(last, 1));
                    writer.Write(last);
                }
            }
        }
    }
ManBOyyy 2019-08-01
  • 打赏
  • 举报
回复
引用 楼主 azhou88 的回复:
数据很多,在winfrom 中如何话很长的曲线图,下面需要有滚动条,可以来回拖动。求教,

mschart也有拖動的,也有滾動條啊
XBodhi. 2019-08-01
  • 打赏
  • 举报
回复
你先用 panel 分层,做一个画布,就有了
azhou88 2019-08-01
  • 打赏
  • 举报
回复
能给一个具体方向吗,谢谢。
  • 打赏
  • 举报
回复
找第三方控件

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧