2020-11-30 c# image 生成chart的,用来代替chart,更加流畅,可以放大缩小,

 

c# image 生成chart的,用来代替chart,更加流畅,可以放大缩小,

散点图,也可以做折线图。

我觉得这个不错的,400k的数据轻松显示,

可以根据图片大小,

现在是

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 散点图
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<double> lx = new List<double>();
            List<double> ly = new List<double>();
            Random random = new Random();
            for (double i = 100; i < 500; i += 1)
            {
                double d = random.NextDouble() * 500;
                lx.Add(i);
                ly.Add(i);
            }
            pictureBox1.Image = image_paint_chart(pictureBox1, lx, ly);
        }
        Image image_paint_chart(PictureBox pictureBox , List<double> lx, List<double> ly)
        {
            int w = pictureBox.Width;
            int h = pictureBox.Height;
            Bitmap bitmap = new Bitmap(w, h);
            //int w = image.Width;
            //int h = image.Height;
            Graphics graphics = Graphics.FromImage(bitmap);
            double xmax = lx.Max();
            double xmin = lx.Min();
            double xmax_min = xmax - xmin;
            double xmax_min2 = (xmax + xmin) / 2;
            double x_w = w / xmax_min;
            double ymax = ly.Max();
            double ymin = ly.Min();
            double ymax_min = ymax - ymin;
            double ymax_min2 = (ymax + ymin) / 2;
            double y_h = h / ymax_min;
            double[] dx = lx.ToArray();
            double[] dy = ly.ToArray();
            Brush brush = new SolidBrush(Color.Green );
            Font font =  new Font("黑体", 10, FontStyle.Regular );
            graphics.DrawString(ymax.ToString(), font, brush, 0, 0);
            graphics.DrawString(ymax_min2.ToString(), font, brush, 0, h / 2);
            graphics.DrawString(ymin.ToString(), font, brush, 0, h - 40);

            graphics.DrawString(xmax .ToString(), font, brush, w-30, h-20);
            graphics.DrawString(xmax_min2.ToString(), font, brush, w/2, h  -20);
            graphics.DrawString(xmin.ToString(), font, brush, 20, h - 20);

            for (int i = 0; i < dx.Length; i++)
            {
                int x = (int)((dx[i] - xmin) * x_w);
                int y = (int)((dy[i] - ymin) * y_h);
                graphics.FillRectangle(brush, x, y, 1, 1);
            }
            return bitmap;
        }
    }
}
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值