[此贴子已经被作者于2006-1-16 14:39:31编辑过]
[此贴子已经被作者于2006-1-16 14:39:31编辑过]
不厚道,sin cos好象不能直接画的吧,那估计要画一组连续线段?
[此贴子已经被作者于2006-1-16 18:44:45编辑过]
我做过画统计分布图的,也是点啊,线啊的,自己画的,
可以画些什么圆啊,椭圆啊,四方形啊,等都好画,
我们老大说网上有好多画图的工具,但是要钱-_-b....
只能苦拉我们这些老百姓啊,惨!!!
public ArrayList arrData = new ArrayList();
public ArrayList arrMonth = new ArrayList();
private void Form1_Load(object sender, System.EventArgs e)
{
arrMonth.Add(1);
arrMonth.Add(2);
arrMonth.Add(3);
arrMonth.Add(4);
arrMonth.Add(5);
arrMonth.Add(6);
arrData.Add(800);
arrData.Add(1000);
arrData.Add(850);
arrData.Add(900);
arrData.Add(750);
arrData.Add(1500);
}
private void button1_Click(object sender, System.EventArgs e)
{
int iCanvasWidth = 1024;
int iCanvasHeight = 768;
Bitmap bitmap = new Bitmap(iCanvasWidth, iCanvasHeight, PixelFormat.Format24bppRgb);
Graphics graph = Graphics.FromImage(bitmap);
graph.Clear(Color.White);
Font font = new Font("MS UI Gothic",12);
SolidBrush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(Color.Black);
pen.EndCap = LineCap.ArrowAnchor;
pen.DashStyle = DashStyle.Solid;
#region 座標軸描画
graph.DrawLine(pen, 200, 600, 650, 600);
graph.DrawLine(pen, 200, 600, 200, 150);
//X軸
graph.DrawLine(Pens.Black, 200 + 90*1, 600, 200 + 90*1, 600 - 5);
graph.DrawLine(Pens.Black, 200 + 90*2, 600, 200 + 90*2, 600 - 5);
graph.DrawLine(Pens.Black, 200 + 90*3, 600, 200 + 90*3, 600 - 5);
graph.DrawLine(Pens.Black, 200 + 90*4, 600, 200 + 90*4, 600 - 5);
graph.DrawLine(Pens.Black, 245 + 90*0, 600, 245 + 90*0, 600 - 2 );
graph.DrawLine(Pens.Black, 245 + 90*1, 600, 245 + 90*1, 600 - 2 );
graph.DrawLine(Pens.Black, 245 + 90*2, 600, 245 + 90*2, 600 - 2 );
graph.DrawLine(Pens.Black, 245 + 90*3, 600, 245 + 90*3, 600 - 2 );
graph.DrawLine(Pens.Black, 245 + 90*4, 600, 245 + 90*4, 600 - 2 );
//Y軸
graph.DrawLine(Pens.Black, 200, 150 + 90*1, 200 + 5, 150 + 90*1);
graph.DrawLine(Pens.Black, 200, 150 + 90*2, 200 + 5, 150 + 90*2);
graph.DrawLine(Pens.Black, 200, 150 + 90*3, 200 + 5, 150 + 90*3);
graph.DrawLine(Pens.Black, 200, 150 + 90*4, 200 + 5, 150 + 90*4);
graph.DrawLine(Pens.Black, 200, 195 + 90*0, 200 + 2, 195 + 90*0);
graph.DrawLine(Pens.Black, 200, 195 + 90*1, 200 + 2, 195 + 90*1);
graph.DrawLine(Pens.Black, 200, 195 + 90*2, 200 + 2, 195 + 90*2);
graph.DrawLine(Pens.Black, 200, 195 + 90*3, 200 + 2, 195 + 90*3);
graph.DrawLine(Pens.Black, 200, 195 + 90*4, 200 + 2, 195 + 90*4);
#endregion
#region 目盛文字,見出し部,マーク文字 描画
double dblY1 = 600;
double dblX1 = 200;
for (int i = 0; i < arrData.Count; i ++)
{
double dblData = Convert.ToDouble(arrData[i]);
double dblY2 = 600 - dblData/2000 * 450;
double dblX2 = Convert.ToDouble(arrMonth[i])/10 * 450 + 200;
graph.DrawLine(Pens.Black, float.Parse(dblX1.ToString()), float.Parse(dblY1.ToString()), float.Parse(dblX2.ToString()), float.Parse(dblY2.ToString()));
dblY1 = dblY2;
dblX1 = dblX2;
}
for (int i = 0; i < 10; i ++)
{
int intX = 450/10*i + 200;
int intY = 600 -450/10*i;
Point ptx = new Point(intX, 620);
Point pty = new Point(150, intY);
graph.DrawString(Convert.ToString(i * 200), font, brush, pty);
graph.DrawString(i.ToString() + "月", font, brush, ptx);
}
#endregion
string strFilePath = @"d:\jackey_gif.gif";
bitmap.Save(strFilePath, ImageFormat.Gif);
font.Dispose();
brush.Dispose();
graph.Dispose();
bitmap.Dispose();
}
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
差不多拉,不明白就问,我也懒的写注释了,
不明白的语句写出来就行!
当然这种方法很傻,但是也很基础的.
[此贴子已经被作者于2006-1-17 15:48:11编辑过]