利用Graphics画出一幅图表
2012-06-27
1000
版权
简介: //获取坐标 private void Form2_MouseMove(object sender, MouseEventArgs e) { this.
//获取坐标
private void Form2_MouseMove(object sender, MouseEventArgs e)
{
this.Text=string.Format("X={0},Y={1}",e.X,e.Y);
}
///
/// 绘制折线图
///
///
///
private void Form2_Paint(object sender, PaintEventArgs e)
{
//首先确定原点
Point centerPoint=new Point(180,340);
//自定义一个带有箭头的画笔
Pen pen = new Pen(Color.Black,1);
pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
//得到当前窗体的Graphics对象
Graphics g = e.Graphics;
//画X轴和Y轴
//g.DrawLine(pens.Black,centerPoint,new Point(centerPoint.X+600,centerPoint.Y));
//g.DrawLine(Pens.Black, centerPoint, new Point(centerPoint.X, 40));
g.DrawLine(pen, centerPoint, new Point(centerPoint.X + 650, centerPoint.Y));
g.DrawLine(pen, centerPoint, new Point(centerPoint.X, 20));
//绘制X轴的点
for (int i = 0; i < 12; i++)
{
g.DrawLine(Pens.Black, new Point(centerPoint.X + (i + 1) 50, centerPoint.Y), new Point(centerPoint.X + (i + 1) 50, centerPoint.Y-5));
g.DrawString((i + 1).ToString() + "月", this.Font, Brushes.Black, new PointF((centerPoint.X + (i + 1) 50) - 7, centerPoint.Y + 3));
}
g.DrawString("X:月份",this.Font,Brushes.Black,new Point(828,355));
//绘制Y轴的点
for (int i = 0; i < 12; i++)
{
g.DrawLine(Pens.Black, new Point(centerPoint.X, centerPoint.Y - (i + 1) 25), new Point(centerPoint.X + 5, centerPoint.Y-(i + 1) 25));
//g.DrawLine(Pens.Black, new Point(centerPoint.X , centerPoint.Y), new Point(centerPoint.X + (i + 1) 50, centerPoint.Y - 5));
g.DrawString(string.Format("{0}",(i+1) 10), this.Font, Brushes.Black, new PointF((centerPoint.X + 5) - 35, (centerPoint.Y - (i + 1) 25)-5));
}
//计算十二个月销售额对应的坐标点
double[] data = { 56.2, 66.3, 98.4, 34.5, 55.6, 87.3, 81.4, 33.3, 46.4, 34.6, 114.5, 80.4};
PointF[] dataPoint = new PointF[data.Length];
for (int i = 0; i < data.Length ; i++)
{
float y = (float)(340 - data[i] 2.5);
float x = centerPoint.X + (i + 1) 50;
PointF point = new PointF(x, y);
dataPoint[i] = point;
}
//绘制十二个点的折线
for (int i = 0; i < data.Length ; i++)
{
g.DrawRectangle(Pens.Black, dataPoint[i].X, dataPoint[i].Y, 2, 2);
}
//将十二个点串成线
g.DrawLines(Pens.Black, dataPoint);
//方法二:Path方法
//GraphicsPath path = new GraphicsPath();//要导入using System.Drawing.Drawing2D;
//for (int i = 0; i < data.Length; i++)
//{
// path.AddRectangle(new RectangleF(dataPoint[i], new SizeF(2, 2)));
//}
//path.AddLines(dataPoint);
//g.DrawPath(Pens.Black, path);
g.DrawString("Y", this.Font, Brushes.Black, new Point(155,7));
g.DrawString("销售额:单位(万元)", this.Font, Brushes.Black, new Point(14, 14));
g.DrawString("某工厂某产品年度销售额图表",this.Font, Brushes.Black, new Point(420,14));
pen.Dispose();
}
//获取坐标
private void Form2_MouseMove(object sender, MouseEventArgs e)
{
this.Text=string.Format("X={0},Y={1}",e.X,e.Y);
}
/// <summary>
/// 绘制折线图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form2_Paint(object sender, PaintEventArgs e)
{
//首先确定原点
Point centerPoint=new Point(180,340);
//自定义一个带有箭头的画笔
Pen pen = new Pen(Color.Black,1);
pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
//得到当前窗体的Graphics对象
Graphics g = e.Graphics;
//画X轴和Y轴
//g.DrawLine(pens.Black,centerPoint,new Point(centerPoint.X+600,centerPoint.Y));
//g.DrawLine(Pens.Black, centerPoint, new Point(centerPoint.X, 40));
g.DrawLine(pen, centerPoint, new Point(centerPoint.X + 650, centerPoint.Y));
g.DrawLine(pen, centerPoint, new Point(centerPoint.X, 20));
//绘制X轴的点
for (int i = 0; i < 12; i++)
{
g.DrawLine(Pens.Black, new Point(centerPoint.X + (i + 1) 50, centerPoint.Y), new Point(centerPoint.X + (i + 1) 50, centerPoint.Y-5));
g.DrawString((i + 1).ToString() + "月", this.Font, Brushes.Black, new PointF((centerPoint.X + (i + 1) 50) - 7, centerPoint.Y + 3));
}
g.DrawString("X:月份",this.Font,Brushes.Black,new Point(828,355));
//绘制Y轴的点
for (int i = 0; i < 12; i++)
{
g.DrawLine(Pens.Black, new Point(centerPoint.X, centerPoint.Y - (i + 1) 25), new Point(centerPoint.X + 5, centerPoint.Y-(i + 1) 25));
//g.DrawLine(Pens.Black, new Point(centerPoint.X , centerPoint.Y), new Point(centerPoint.X + (i + 1) 50, centerPoint.Y - 5));
g.DrawString(string.Format("{0}",(i+1)10), this.Font, Brushes.Black, new PointF((centerPoint.X + 5) - 35, (centerPoint.Y - (i + 1) 25)-5));
}
//计算十二个月销售额对应的坐标点
double[] data = { 56.2, 66.3, 98.4, 34.5, 55.6, 87.3, 81.4, 33.3, 46.4, 34.6, 114.5, 80.4};
PointF[] dataPoint = new PointF[data.Length];
for (int i = 0; i < data.Length ; i++)
{
float y = (float)(340 - data[i] 2.5);
float x = centerPoint.X + (i + 1) 50;
PointF point = new PointF(x, y);
dataPoint[i] = point;
}
//绘制十二个点的折线
for (int i = 0; i < data.Length ; i++)
{
g.DrawRectangle(Pens.Black, dataPoint[i].X, dataPoint[i].Y, 2, 2);
}
//将十二个点串成线
g.DrawLines(Pens.Black, dataPoint);
//方法二:Path方法
//GraphicsPath path = new GraphicsPath();//要导入using System.Drawing.Drawing2D;
//for (int i = 0; i < data.Length; i++)
//{
// path.AddRectangle(new RectangleF(dataPoint[i], new SizeF(2, 2)));
gibbon.92demo.com/
gazelle.92demo.com/
fox.92demo.com/
ferret.92demo.com/
abyss.92demo.com/
elephant.92demo.com/
dolphin.92demo.com/
deer.92demo.com/
chimpanzee.92demo.com/
camel.92demo.com/
calf.92demo.com/
buffalo.92demo.com/
bison.92demo.com/
beaver.92demo.com/
bear.92demo.com/
bat.92demo.comm/
badger.92demo.com/
armadillo.92demo.com/
anteater.92demo.com/
academic.92demo.com/
abut.92demo.com/
abusive.92demo.com/
abuse.92demo.com/
abundantly.92demo.com/
abundant.92demo.com/
abundance.92demo.com/
absurdly.92demo.com/
absurdity.92demo.com/
absurd.92demo.com/
abstruse.92demo.com/
abstraction.92demo.com/
abstracted.92demo.com/
abstract.92demo.com/
abstinent.92demo.com/
abstinence.92demo.com/
abstentious.92demo.com/
abstention.92demo.com/
abstemious.92demo.com/
abstain.92demo.com/
absorption.92demo.com/
absorbing.92demo.com/
absorb.92demo.com/
absolve.92demo.com/
absolutely.92demo.com/
absolute.92demo.com/
absentmindedness.92demo.com/
absently.92demo.com/
absenteeism.92demo.com/
absentee.92demo.com/
absent-minded.92demo.com/
absent.92demo.com/
absence.92demo.com/
abscond.92demo.com/
abscission.92demo.com/
abscissa.92demo.com/
abscess.92demo.com/
abruptly.92demo.com/
abruption.92demo.com/
abrupt.92demo.com/
abrogation.92demo.com/
abrogate.92demo.com/
abroad.92demo.com/
abridgment.92demo.com/
abridgement.92demo.com/
abridge.92demo.com/
abreast.92demo.com/
abrasive.92demo.com/
abrasion.92demo.com/
Abraham.92demo.com/
abrade.92demo.com/
aboveboard.92demo.com/
above-mentioned.92demo.com/
above.92demo.com/
about.92demo.com/
abound.92demo.com/
abortive.92demo.com/
abortion.92demo.com/
abort.92demo.com/
aborigines.92demo.com/
aborigine.92demo.com/
aboriginal.92demo.com/
abominate.92demo.com/
abominable.92demo.com/
abolitionist.92demo.com/
abolition.92demo.com/
abolish.92demo.com/
abode.92demo.com/
aboard.92demo.com/
abnormality.92demo.com/
abnormal.92demo.com/
abnegation.92demo.com/
abnegate.92demo.com/
ably.92demo.com/
ablution.92demo.com/
able-bodied.92demo.com/
able.92demo.com/
ablaze.92demo.com/
ablate.92demo.com/
abjure.92demo.com/
abject.92demo.com/
ability.92demo.com/
abiding.92demo.com/
abide.92demo.com/
abhorrent.92demo.com/
abhorrence.92demo.com/
abhor.92demo.com/
abeyance.92demo.com/
abettor.92demo.com/
abet.92demo.com/
aberration.92demo.com/
aberrant.92demo.com/
abend.92demo.com/
abecedarian.92demo.com/
abeam.92demo.com/
abduction.92demo.com/
abduct.92demo.com/
abdominal.92demo.com/
abdomen.92demo.com/
abdication.92demo.com/
abdicate.92demo.com/
ABC.92demo.com/
Abby.92demo.com/
abbreviation.92demo.com/
abbreviate.92demo.com/
abbot.92demo.com/
abbey.92demo.com/
abatement.92demo.com/
abate.92demo.com/
abash.92demo.com/
abase.92demo.com/
abandonment.92demo.com/
abandoned.92demo.com/
abandon.92demo.com/
abaft.92demo.com/
abacus.92demo.com/
aback.92demo.com/
milksop.92demo.com/
milkpump.92demo.com/
milkstone.92demo.com/
milkwort.92demo.com/
milkweed.92demo.com/
milky.92demo.com/
mill.92demo.com/
millboard.92demo.com/
millable.92demo.com/
millability.92demo.com/
millcourse.92demo.com/
milldam.92demo.com/
millennium.92demo.com/
millennial.92demo.com/
millennia.92demo.com/
millenary.92demo.com/
millenarian.92demo.com/
millefiori.92demo.com/
Milleorina.92demo.com/
Milleporina.92demo.com/
millepore.92demo.com/
millepede.92demo.com/
milleped.92demo.com/
milletgrass.92demo.com/
millet.92demo.com/
millesimal.92demo.com/
millerite.92demo.com/
millerayes.92demo.com/
miller.92demo.com/
millicurie.92demo.com/
millicoulomb.92demo.com/
millibarometer.92demo.com/
millibarn.92demo.com/
millibar.92demo.com/
milliatom.92demo.com/
milliarium.92demo.com/
milliard.92demo.com/
milliamperemeter.92demo.com/
milliampere.92demo.com/
milliammeter.92demo.com/
milli.92demo.com/
millicycle.92demo.com/
millidarcy.92demo.com/
milliequivalent.92demo.com/
millihenry.92demo.com/
milligramme.92demo.com/
milligramequivalent.92demo.com/
milligrame.92demo.com/
Milligramage.92demo.com/
milligram.92demo.com/
milligauss.92demo.com/
milligamma.92demo.com/
millifarad.92demo.com/
millihertz.92demo.com/
abacist.92demo.com/
abaci.92demo.com/
abaca.92demo.com/
millimaxwell.92demo.com/
millilux.92demo.com/
millilitre.92demo.com/
milliliter.92demo.com/
millilambert.92demo.com/
millilambda.92demo.com/
abacus.92demo.com/
abaculus.92demo.com/
abacterial.92demo.com/
aback.92demo.com/
Abaddon.92demo.com/
milkpox.92demo.com/
milkpea.92demo.com/
milkman.92demo.com/
milkmaid.92demo.com/
milking.92demo.com/
milkiness.92demo.com/
milkglass.92demo.com/
milkfat.92demo.com/
milker.92demo.com/
milk.92demo.com/
milium.92demo.com/
militiaman.92demo.com/
militia.92demo.com/
militate.92demo.com/
military.92demo.com/
militarize.92demo.com/
militarization.92demo.com/
militaristic.92demo.com/
militarist.92demo.com/
militarism.92demo.com/
militarise.92demo.com/
militarisation.92demo.com/
militarily.92demo.com/
militant.92demo.com/
militancy.92demo.com/
militance.92demo.com/
milipertine.92demo.com/
miliolite.92demo.com/
Miliolina.92demo.com/
Miliolidae.92demo.com/
miliolid.92demo.com/
Miliolacea.92demo.com/
Miliola.92demo.com/
milimetre.92demo.com/
milieu.92demo.com/
Milichiidae.92demo.com/
miliary.92demo.com/
miliaria.92demo.com/
milia.92demo.com/
milfoil.92demo.com/
milestone.92demo.com/
Milesian.92demo.com/
miler.92demo.com/
milepost.92demo.com/
mileometer.92demo.com/
milenperone.92demo.com/
mileage.92demo.com/
mile.92demo.com/
mildness.92demo.com/
mildly.92demo.com/
mildewy.92demo.com/
mildewproof.92demo.com/
mildewed.92demo.com/
mildew.92demo.com/
milden.92demo.com/
mild.92demo.com/
milch.92demo.com/
Milbex.92demo.com/
milarite.92demo.com/
Milanese.92demo.com/
Milan.92demo.com/
milage.92demo.com/
milady.92demo.com/
miladi.92demo.com/
mil.92demo.com/
mikvah.92demo.com/
etee.92demo.com
gife.92demo.com
gil32t.92demo.com
gibb43on.92demo.com
gazg4er5lle.92demo.com
g3gerelle.92demo.com
ferret2.92demo.com
abyss54.92demo.com
elephant3.92demo.com
dolphin53.92demo.com
deerhg.92demo.com
impanzee.92demo.com
came2l.92demo.com
cal1f.92demo.com
bubisoalo.92demo.com
bieeson.92demo.com
beaveear.92demo.com
beaear.92demo.com
baeaeat.92demo.com
badgedidir.92demo.com
ardgedillo.92demo.com
antdilter.92demo.com
dilademic.92demo.com //}
//path.AddLines(dataPoint);
//g.DrawPath(Pens.Black, path);
g.DrawString("Y", this.Font, Brushes.Black, new Point(155,7));
g.DrawString("销售额:单位(万元)", this.Font, Brushes.Black, new Point(14, 14));
g.DrawString("某工厂某产品年度销售额图表",this.Font, Brushes.Black, new Point(420,14));
pen.Dispose();