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;
}
}
}