• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
平衡适可而止
博客园    首页    新随笔    联系   管理    订阅  订阅

怎样将.dotnetcharting控件生成的图标打印

 

思想是将chart生成的报表转换成图片 ,然后打印。详细代码如下:

            chart1.TempDirectory = "temp";
            chart1.Debug = true;
            chart1.Palette = new Color[] { Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255) };

            chart1.Type = ChartType.Combo;
            chart1.Width = 600;
            chart1.Height = 350;
            chart1.Title = ".netCHARTING Sample";
           
            chart1.LegendBox.Visible = false;
            chart1.DefaultSeries.Type = SeriesType.Line;


            SeriesCollection mySC = getRandomData();    //数据集合
            // Add the random data.
            chart1.SeriesCollection.Add(mySC);
            //chart1.
        }
        SeriesCollection getRandomData()
        {
            Random myR = new Random(1);
            int startVal = 12000;
            SeriesCollection SC = new SeriesCollection();
            int a = 0;
            int b = 0;
            for (a = 1; a < 2; a++)
            {
                Series s = new Series("Series " + a.ToString());
                for (b = 1; b < 10; b++)
                {
                    Element e = new Element();
                    //e.XDateTime = DateTime.Now.AddDays(b);
                    e.XValue = b * 1;
                    e.YValue = startVal = startVal + (-7 + myR.Next(20));
                    s.Elements.Add(e);
                }
                SC.Add(s);
            }
            return SC;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //PrintDocument pd = new PrintDocument();
            printDocument1.PrintPage += new PrintPageEventHandler
                (this.PrintImageHandler);
            this.printDialog1.AllowSomePages = true;
            this.printDialog1.ShowHelp = true;
            printDialog1.Document = printDocument1;

            DialogResult Rest = printDialog1.ShowDialog();
            if (Rest == DialogResult.OK)
            {
                printDocument1.Print();
            }

           
        }

        private void PrintImageHandler(object sender,
            PrintPageEventArgs ppeArgs)
        {

            Image curImage = chart1.GetChartBitmap();
            Graphics g = ppeArgs.Graphics;
           


            /*switch(this.s)
            {
           
            }*/
            if (curImage != null)
            {
                // Draw Image using the DrawImage method
                g.DrawImage(curImage, 100, 100,
                    curImage.Width, curImage.Height);
            }
        }

posted @ 2010-04-01 15:25  平衡适可而止  阅读(372)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3