ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Embedding Image in Email
Posted by Anand Kumar on Jan-19-2011 21:54
HI All,
  Every One I have been trying to embed the chart generated Image into the mail body for sending chart as an image to the Mail address.
The problem is that i'm not able to display the image in the Mail.The place where i'm displaying the image coming as a picture box with empty image.But when i send the data to a logger or else to console it is displaying the data present in the image variable which i'm displaying in the email body.The Code sample is below:-


//Data to be displayed
double[] data = {85, 156, 179.5, 211, 123};

//The labels for the bar chart
String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
Logger.info(this.getClass(), "After initializing the data and labels");

//Create a XYChart object of size 250 x 250 pixels
XYChart c = new XYChart(200, 200);

//Set the plotarea at (30, 20) and of size 200 x 200 pixels
c.setPlotArea(30, 20, 150, 150);

//Add a bar chart layer using the given data
c.addBarLayer(data);
Logger.info(this.getClass(), "after adding data to bar layer ");

//Set the labels on the x axis.
c.xAxis().setLabels(labels);

Logger.info(this.getClass(), "setting x-axis labels");


//output the chart
java.awt.Image image =  c.makeImage();
System.out.println("Image Data"+image);
CTELogger.info(this.getClass(), "This is the Image data"+image);
//Include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: US${value}K'");


The data for image i'm pasting to the image tag is below:-

buffer.append(<img src='"+image+"'"+
   "usemap='#map1' border='0'>"+
"<map name='map1'>"+imageMap1+"</map>" );

These whole data is in java class for sending the image.Kindly correct me where ever need.Thanx, for the help provided by all in advance.Need it Urgently.
Spent lot of time for resolving the issue.

  Re: Embedding Image in Email
Posted by Peter Kwan on Jan-20-2011 01:00
Hi Anand,

This question does not seem to be related to ChartDirector, but to how to create an email.

I see you are inserting an <IMG> tag in the email. Note that the SRC attribute of the <IMG> tag should be an URL, not the image data. If you are not familiar with what is a URL or how to use the <IMG> tag, you may refer to the HTML documentation for details.

If you want to use <IMG> tag in an email, the standard method is to save the chart as a PNG, JPG or GIF image in a server that is accessible by the user (the person who reads the email). Then the SRC can be set to the URL of that image.

Some people may use CID to inline the image in the email, but this is not supported by all email readers. Also, many spam filters consider any email that has inline images as spam.

A third method you may consider is to send the chart image as a file attachment.

If you are not famiiliar with how to create an email, please refer to the email standard documentation, or you may consider to use a third party package that can create email.

Regards
Peter Kwan

  Re: Embedding Image in Email
Posted by Anand Kumar on Jan-20-2011 20:04
First of all Sorry for not understanding the TAG properly and confusing you.Thanx Peter Kwan for your reply and valuable suggestion for my query.Your valuable information sovled my issue for sending the image through mail and i wish to show the code from which generated the Image in JAVA.
//output the java.awt.Image data
Image image =  c.makeImage();

String ext = "png";
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
bufferedImage.getGraphics().drawImage(image, 0, 0, null);

File file = new File("imageName.png");
ImageIO.write(bufferedImage, ext, file);


This will place the PNG Image in the current Directory.Now you can show this image where ever needed.

Thanx once again Peter Kwan for the Information.....

  Re: Embedding Image in Email
Posted by Peter Kwan on Jan-21-2011 02:12
Hi Anand,

If you like, you may also use BaseChart.makeChart to create the chart directly as an image file (instead of creating as a java.awt.Image and use Java code to save it as a PNG file). For example:

c.makeChart("/path/to/aaa.png");

Hope this can help.

Regards
Peter Kwan

  Re: Embedding Image in Email
Posted by Anand Kumar on Jan-21-2011 14:08
HI Peter,
          Thanx for the suggestion Peter. Right from the beginning of generating the Image, have been thinking how to save it in other format rather than awt image.As i know awt components are heavy when compared with others. So, you made me to solve the Issue.
With the help of your piece of code this is what i did to save the Image:-
String ext = "png";
boolean savedImage = c.makeChart("/path/to/image/");
File file = new File("/path/to/image");
BufferedImage bufferedImage = ImageIO.read(file);
ImageIO.write(bufferedImage, ext, file);

If i'm wrong in saving the image as you told please correct me.
Thanx Peter.

  Re: Embedding Image in Email
Posted by Peter Kwan on Jan-21-2011 15:22
Hi Anand,

You just need one line of code:

c.makeChart("/path/to/aaa.png");

The above code saved the chart as an image called "aaa.png" in the directory "/path/to".

For example:

c.makeChart("c:/xyz/ppp/qqq.png");

The above saved the image file to "c:/xyz/ppp/qqq.png". Note that "c:/xyz/ppp" must already exist (ChartDirector will not automatically create the subdirectory), and it must be readable/writable by the web server.

Also, note that the path above is a file system path, not a URL. For example, the leading "/" means the root of the hard disk, not the root of the web document directory.

Hope this can help.

Regards
Peter Kwan