http://blog.sina.com.cn/s/blog_50d936c40100djss.html###
这段时间要用C#做个项目,需要画一个曲线图,在网上找了半天资料都没找到合适的。不仅感叹C#和JAVA的区别。JAVA有很多开源项目,大大方便了其他人的使用。像在做统计图这一块,有就专门的JFreeChart组件,对于做统计图,十几行代码就搞定了。
最后总算在一个网友提供的地址,才找到了一个别人做的比较好的源代码,粘贴如下:
柱状图的完整代码:
绘制柱状统计图的完整代码
private void CreateImage()
{
int height = 500, width = 700;
Bitmap image = new Bitmap(width, height);
//创建Graphics类对象
Graphics g = Graphics.FromImage(image);
try
{
//清空图片背景色
g.Clear(Color.White);
Font font = new Font("Arial", 10, FontStyle.Regular);
Font font1 = new Font("宋体", 20, FontStyle.Bold);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height),
Color.Blue, Color.BlueViolet, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
// Brush brush1 = new SolidBrush(Color.Blue);
g.DrawString(this.ddlTaget.SelectedItem.Text + " " + this.ddlYear.SelectedItem.Text +
" 成绩统计柱状图", font1, brush, new PointF(70, 30));
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush, 1);
//绘制线条
//绘制横向线条
int x = 100;
for (int i = 0; i < 14; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x