| dicklarsson | Post date: 2007-03-01 09:50Visualize your domino data using Open Source java
http://www.jfree.org
This code shows how easy it is to create a diagram/chart and to save it as a file.
The code asks explorer.exe to display the image. (windows only)
Its just an example, feel free to do what ever you want with it.
Great for web applications
Example image, http://www.ekakan.com/www/web.nsf/JavaCharts.png
- Go to JFree.Org
- Download the latest version of JFreeChart
- Extract the files to a temp directory
- Create a new notes java agent.
- Set Runtime target to "none"
- Click Edit Project and add the jar files found in the temp directory where you extacted JFreeChart to your agent.
- Paste the code showed in Example 1
Example 1
import lotus.domino.*;
import org.jfree.chart.*;
import org.jfree.data.*;
import org.jfree.data.general.*;
import java.util.*;
import java.io.*;
//@author: dick.larsson@ekakan.com
//+46(0)706 - 33 23 68
public class JavaAgent extends AgentBase
{
public void NotesMain()
{
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
HashMap map = new HashMap();
map.put("Pierre", new Integer(178));
map.put("Dick", new Integer(87));
map.put("Ola", new Double(200));
map.put("Random", new Double( (Math.random() * 200)));
writeChartToDisk("Diagram", "c:\\test.jpg", map);
} catch (Exception e)
{
e.printStackTrace();
}
}
private void writeChartToDisk(String title, String fileName, Map map)
{
//put map values in to a DefaultPieDataset
Iterator iterator = map.keySet().iterator();
DefaultPieDataset pieDataset = new DefaultPieDataset();
while (iterator.hasNext())
{
Object o = iterator.next();
Object o2 = map.get(o);
pieDataset.setValue((String) o, (Number) o2);
}
//Create the actual chart
JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, true, true, true);
//Write chart to disk as JPG file, and ask explorer.exe to show it.
//You could extract the file to the html directory of the domino server or attach to a notes-document
try
{
FileOutputStream fos = new FileOutputStream( fileName);
ChartUtilities.writeChartAsJPEG(fos, 1, chart, 750, 400);
fos.flush();
fos.close();
Runtime run = Runtime.getRuntime();
run.exec("explorer.exe " + fileName );
} catch (Exception e)
{
e.printStackTrace(getAgentOutput());
}
}
}
|
JavaCharts.png
|
| Nathan T Freeman | Post date: 2007-03-10 01:04You can find a demo implementation at http://nsftools.com
I used it for the basis of a fairly elaborate charting engine for a customer once. Good stuff
|
| Jonas Israelsson | Post date: 2007-03-11 14:12Another great one from Dick.
|