| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2296 人关注过本帖
标题:求一C#柱状图,曲线图的源码
只看楼主 加入收藏
xyfabc
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-11-23
收藏
 问题点数:0 回复次数:6 
求一C#柱状图,曲线图的源码
求一C#柱状图,曲线图的源码

实现效果如下:纵列显示数据量,横列显示12个月。每个月有10个柱要显示。不知哪位高人有比较好看的图表及源码,请指教!万分感谢!!
我的QQ:176782675

搜索更多相关主题的帖子: 柱状图 曲线图 源码 效果 图表 
2006-11-23 10:16
CrazyWeed0907
Rank: 2
等 级:新手上路
威 望:5
帖 子:1385
专家分:0
注 册:2006-5-30
收藏
得分:0 

自己随便画个就行了,

做一个好的比较费劲,网上应该有免费图表控件下载的,你去找找吧

[此贴子已经被作者于2006-11-23 10:25:24编辑过]


“十步杀一人,千里不留行。事了拂衣去,深藏身与名。”
2006-11-23 10:23
wkm2000
Rank: 1
等 级:新手上路
帖 子:119
专家分:0
注 册:2006-3-6
收藏
得分:0 
http://terrylee.cnblogs.com/archive/2005/12/18/252178.html[/URL]
这是个画柱状图的!
去看看吧!

MSN:wkm821215@ OICQ:49297869 ^_^
2006-11-23 16:21
zhutao8520
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-5-15
收藏
得分:0 
谢谢 谢谢 非常有用啊
再次感谢
2007-05-18 00:44
ghbjimmy
Rank: 2
等 级:论坛游民
帖 子:49
专家分:19
注 册:2010-5-17
收藏
得分:0 
要是有简单的演示程序就好了!
2011-06-07 11:42
sally103
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-1-2
收藏
得分:0 
柱状图,代码如下:
注意:请注意参数 chartTable 图形里的一些元素需要从chartTable里面取。具体请查看代码。

        //Render是图形大标题,图开小标题,图形宽度,图形长度,饼图的数据集和饼图的数据集  
        public Image Render(string title, int width, int height, DataTable chartTable)
        {
            Bitmap bm = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bm);
            g.Clear(Color.White);

            DataTable dt = chartTable;
            const int top = 30;
            const int left = 35;

            if (width < left * 2 || height < top * 2)
            {
                g.DrawString("绘图区域太小", new Font("Tahoma", 8),
                    Brushes.Blue, new PointF(0, 0));
                return bm;
            }

            //计算最高的点  
            float highPoint = 1;
            foreach (DataRow dr in dt.Rows)
            {
               if (highPoint < Convert.ToSingle(dr[0]))
                {
                    highPoint = Convert.ToSingle(dr[0]);
                }

                if (highPoint < Convert.ToSingle(dr[1]))
                {
                    highPoint = Convert.ToSingle(dr[1]);
                }
            }
            try
            {
                //画大标题  
                g.DrawString(title, new Font("Tahoma", 12), Brushes.Black, new PointF(2, 2));
                StringFormat drawFormat = new StringFormat();
                drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;

                g.DrawString("[红--" + dt.Columns[0].ToString() + "]", new Font("Tahoma", 8),
                    Brushes.Red, new PointF(2, top), drawFormat);
                g.DrawString("[蓝--" + dt.Columns[1].ToString() + "]", new Font("Tahoma", 8),
                    Brushes.Blue, new PointF(17, top), drawFormat);

                //画条形图  
                float barWidth = (Convert.ToSingle(width) - left) / (dt.Rows.Count * 3 + 1);
                PointF barOrigin = new PointF(left + barWidth, 0);
                float barHeight = dt.Rows.Count;
                float topFontSize = (barWidth / highPoint.ToString().Length);
                 
                if (topFontSize > 2*top/3)
                {
                    topFontSize = 2*top/3;
                }
                if (topFontSize < 5)
                {
                    topFontSize = 5;
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //底部字体的大小
                    float bottomFontSize = (2 * barWidth / dt.Rows[i][2].ToString().Length) + 2;
                    if (bottomFontSize > 2 * top / 3)
                    {
                        bottomFontSize = 2 * top / 3;
                    }

                    barHeight = Convert.ToSingle(dt.Rows[i][0]) * (height - 2 * top) / highPoint * 1;
                    barOrigin.Y = height - barHeight - top;
                    g.FillRectangle(new SolidBrush(Color.Red), barOrigin.X, barOrigin.Y, barWidth, barHeight);
                    //柱状图底部
                    g.DrawString(dt.Rows[i][2].ToString(), new Font("Tahoma", bottomFontSize), Brushes.Black,
                        new PointF(barOrigin.X, height - top));
                    //柱状图顶部
                    g.DrawString(dt.Rows[i][0].ToString(), new Font("Tahoma", topFontSize), Brushes.Red,
                        new PointF(barOrigin.X, barOrigin.Y - 3*topFontSize/2));

                    barOrigin.X = barOrigin.X + barWidth;


                    barHeight = Convert.ToSingle(dt.Rows[i][1]) * (height - 2 * top) / highPoint * 1;
                    barOrigin.Y = height - barHeight - top;
                    g.FillRectangle(new SolidBrush(Color.Blue), barOrigin.X, barOrigin.Y, barWidth,  

barHeight);
                    //柱状图顶部
                    g.DrawString(dt.Rows[i][1].ToString(), new Font("Tahoma", topFontSize), Brushes.Blue,
                        new PointF(barOrigin.X, barOrigin.Y - 3 * topFontSize/2));
                    barOrigin.X = barOrigin.X + (barWidth * 2);
                }

                //设置边  
                g.DrawLine(new Pen(Color.Blue, 2), new Point(left, top),
                    new Point(left, height - top));

                g.DrawLine(new Pen(Color.Blue, 2), new Point(left, height - top),
                    new Point(left + width, height - top));

                g.Dispose();
                return bm;
            }
            catch
            {
                return bm;
            }
        }
2011-08-17 10:55
菜鸟变青头
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-4-18
收藏
得分:0 
msChart
2011-09-16 12:16
快速回复:求一C#柱状图,曲线图的源码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020683 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved