您的位置:首页 > 其它

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

2010-04-01 15:25 435 查看
思想是将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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: