Sign in to follow this  
pca

Saving and mailing charts

Recommended Posts

Hi everyone

 

 

 

In the FAQ section you mention that it is possible to mail the charts. How?

 

 

 

Due to the security problems mentioned there I'm trying to mail the chart after saving it as a file in the server by modifying the FusionChartsSave.jsp. The problem is that I want to have the options of saving the chart as an image, and mail it too. But if I change the FusionChartsSave.jsp file I can only do one of them. Which brings me to my question. Is is possible to send a parameter to the FusionChartsSave.jsp file or even to change the imageSaveURL according to the intended action?

 

 

 

Thanks in advance :D

Share this post


Link to post
Share on other sites

Hi,

You can send URL encoded query string with in imageSaveURL.

 URL

 FusionChartsSave.jsp?CID=2&KB=1

 

 encoded URL

 FusionChartsSave.jsp%3FCID%3D2%26KB%3D1

i.e

 <chart ......  imageSaveURL='FusionChartsSave.jsp%3FCID%3D2%26KB%3D1'  ... >

Thanks for implementing this and stretching FusionCharts to this extent. Could you please share the code with the FusionCharts community so that you could help out a huge number of FusionCharts developers.

Thanks again

Edited by Guest

Share this post


Link to post
Share on other sites

One of the parameters I had in mind was the destination mail. By passing them to the jsp file that way I would need to redraw the chart everytime I wanted to send a mail to a different destination, right?

 

 

 

Is there a way around that?

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Another option could be to save the charts on server, though this is experimental:

 

- In Java, create an instance of browser on server

 

- Load the chart in that (guess would have to build temporary HTML files with chart code)

 

- Use JavaScript API to automatically call the save script

 

- When saved, close the browser instance

 

- Use a queue manager to manage all the instances of browser.

Share this post


Link to post
Share on other sites

So my choices are to reload the chart on the client side, or load it on the server side.

 

 

 

Is there no setImageSaveURL? It would be immensely helpful.

 

 

 

I can now send an email with the chart as an attachment, but I'm left with another problem. After I send the email, it moves to a blank page. If I redirect to the previous pages it loses the components that were on it. How can I stay on the same page? Like what happens when it sends back the image file to the client side.

 

 

 

Anyway, here is what I have so far. For now there are no settings defined by parameters. Hope it helps someone :D

 

 

 

<%@ page import="java.io.OutputStream"%>

 

<%@ page import="java.io.PrintWriter"%>

 

<%@ page import="java.io.File"%>

 

<%@ page import="java.awt.Color"%>

 

<%@ page import="java.awt.Graphics"%>

 

<%@ page import="java.awt.image.BufferedImage"%>

 

<%@ page import="javax.imageio.ImageIO"%>

 

<%@ page import="java.util.Properties"%>

 

<%@ page import="javax.mail.*"%>

 

<%@ page import="javax.mail.internet.*"%>

 

<%@ page import="javax.activation.*"%>

 

 

 

<%

 

//Decoded data from charts.

 

String data="";

 

//Rows of color values.

 

String[] rows;

 

//Width and height of chart.

 

int width=0;

 

int height=0;

 

//Default background color of the chart

 

String bgcolor="";

 

Color bgColor;

 

 

 

(.....

 

rest of the script given by FusioCharts

 

.....)

 

 

 

for (int k=1; k<=r; k++){

 

//Draw each pixel

 

gr.setColor(new Color(Integer.parseInt(c,16)));

 

gr.fillRect(ri, i,1,1);

 

//Increment horizontal row count

 

ri++;

 

}

 

}else{

 

//Just increment horizontal index

 

ri = ri + r;

 

}

 

}

 

}

 

 

 

// No need to send the image file as a response so you can comment it, if you like

 

 

 

String filename = "FusionChart" + System.currentTimeMillis() + ".jpg" ;

 

File outfile = new File(filename) ;

 

ImageIO.write(chart, "jpeg", outfile);

 

 

 

String from="your@mail";

 

String to="yourdestination@mail";

 

String host="you.mail.smtp.server";

 

// String port="111"; // define if needed

 

 

 

// Get system properties

 

Properties props = System.getProperties();

 

 

 

// Setup mail server

 

props.put("mail.smtp.host", host);

 

// props.put("mail.smtp.port", port); // define if needed

 

// props.put("mail.smtp.auth", "true"); // define if needed

 

 

 

// Get session

 

Session s = Session.getInstance(props, null);

 

 

 

// Define message

 

MimeMessage message = new MimeMessage(s);

 

message.setFrom(new InternetAddress(from));

 

message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

 

message.setSubject("A sugestive subject here");

 

 

 

MimeBodyPart messageBodyPart = new MimeBodyPart();

 

 

 

//fill message

 

messageBodyPart.setText("any text you want to send");

 

 

 

Multipart multipart = new MimeMultipart();

 

multipart.addBodyPart(messageBodyPart);

 

 

 

// Part two is attachment

 

messageBodyPart = new MimeBodyPart();

 

DataSource source = new FileDataSource(outfile);

 

messageBodyPart.setDataHandler(new DataHandler(source));

 

messageBodyPart.setFileName(filename);

 

multipart.addBodyPart(messageBodyPart);

 

 

 

// Put parts in message

 

message.setContent(multipart);

 

 

 

// Send the message

 

Transport transport = s.getTransport("smtp");

 

transport.connect(host, "your username here","your password here");

 

transport.send( message,message.getAllRecipients() );

 

transport.close() ;

 

%>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this