Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Excel graphs in .NET using C sharp

Status
Not open for further replies.

piofenton

Instructor
Jul 12, 2002
33
IE
Hi all,
I have generated some data in my application for which I am using Excel to determine a linear relationship. I want to display the resultant graph on my windows form. So far I have tried using the Office Web Chart component but with no success. Is there anyway I can use a picture pox to achieve the same thing? Or any other ideas?
Cheers!
 
Hi piofenton

Same problem here, but I got a little farther (still can't get it to work, though, but maybe you'll have better luck).

There are two ways I found to get the chart as an image:

1. Once your chart is generated, you can copy the image of it to the clipboard, and then save the contents of the clipboard to an image file.

Code:
System.Drawing.Image tempImage=null;

//copy image to clipboard
ExcelChartObject.Chart.CopyPicture ( XlPictureAppearance.xlScreen, 
XlCopyPictureFormat.xlBitmap,
XlPictureAppearance.xlScreen  );

if (Clipboard.GetDataObject() != null)
{
	IDataObject data = Clipboard.GetDataObject();
	if (data.GetDataPresent (DataFormats.Bitmap ))
	{
		tempImage = (Bitmap) data.GetData (DataFormats.Bitmap );
		// save image to file
		tempImage.Save (ImageFileName);
	}
}

// ExcelChartImage is the Image cont5rol on the web form. Assign the URL to the imagefile we just saved
ExcelChartImage.ImageUrl = ImageFileName;

2. Export the chart's image directly to a file
Code:
ExcelChart.Export (ImageFileName, "GIF", false);

On my end, I have tried both methods, as well as trying to use Microsoft Excel Chart 10 (and 11). All three attempts failed miserably. The first two fail with a wierd exception as soon as I try to do anything with the chart object (in a server app only; standalone app is fine). I've raised thread732-1289097, but so far no answers :(

And the COM option fails because after I put it on my form (again, web form only. Standalone is fine), the control has no ID (I have to assign one manually) and double clicking on it does not take me to the code. Even if I try typing the control ID and a period, intellisense does not pick up its methods and properties. Compiling just results in an error.

I think there's something off with my web projects, but cannot for the life of me figure it out. I do have Office 2003 installed, so I don't think it's licensing. But you never know ...

I hope you have better luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top