Here's the code for my example.
I see that the image map is generated but is returned empty, How do i ensure that a image-map is generated for XYZDataset?
Any tutorial that shows ImageMaps/URLs/ToolTips generated for a Bubble Chart? Plz help me out
Code: Select all
/* JSP Page */
<%@ page import = "testchart.*" %>
<%@ page import = "java.io.PrintWriter" %>
<%@ page import = "java.util.ArrayList" %>
<%@ page import = "java.util.Iterator" %>
<%
String filename = ChartGen.generateBubbleChart(session, new PrintWriter(out));
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<html>
<head>
<link rel="stylesheet" href="sample.css" type="text/css"/>
<title>Bubble Sample</title>
</head>
<body>
<img src="<%= graphURL %>" width=800 height=600 border=0 usemap="#<%= filename %>">
</body>
</html>
/* ---------------------------------------------------------------------- */
/* Code for the ChartGen class */
public class ChartGen {
public static String generateBubbleChart(HttpSession session,PrintWriter pw) {
String filename = null;
List<RowItem> data;
try {
// This generates random data stored in List
RowGenerator s = new RowGenerator();
data = s.getResults();
XYZDataset dataset = new XYZData();
XYZSeries series = new XYZSeries("Bubbles");
for(RowItem row :data) {
series.addData(row.getPerformance(), row.getPerformanceBPT(), row.getDeviation()/10);
System.out.println(" TEST" +row.getPerformance()+" "+ row.getPerformanceBPT() +" "+ (row.getDeviation()/10));
}
((XYZData)dataset).addSeries(series);
System.out.println(dataset.getSeriesCount());
String xval = dataset.getSeriesKey(0).toString();
//String yval = dataset.getSeriesKey(0).toString();
JFreeChart chart = ChartFactory.createBubbleChart("Flex", xval,"yval", dataset, PlotOrientation.VERTICAL, true, true, true);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, 800,600, session);
ChartUtilities.writeImageMap(pw, filename, info, false);
pw.flush();
}
/* -------------------------------------------------------------------------------- */
/* XYZ Data */
package testchart;
import java.util.Vector;
import org.jfree.data.xy.AbstractXYZDataset;
import org.jfree.data.xy.XYZDataset;
public class XYZData extends AbstractXYZDataset implements XYZDataset{
private Vector seriesTable = new Vector();
private int seriesCount = 0;
/**
* This method adds a serie to the dataset.
*
* @param serie the serie to be added.
*/
public void addSeries(XYZSeries serie) {
seriesTable.addElement((Object) serie);
seriesCount++;
}
/**
* Returns the number of series in the dataset.
*
* @return the series count.
*/
public int getSeriesCount() {
return seriesCount;
}
/**
* Returns the name of a series.
*
* @param series the series (zero-based index).
*
* @return the name of the series.
*/
public String getSeriesName(int series) {
return ((XYZSeries)seriesTable.get(series)).getName();
}
/**
* Returns the number of items in a series.
*
* @param series the series (zero-based index).
*
* @return the number of items within the series.
*/
public int getItemCount(int series) {
return ((XYZSeries)this.seriesTable.get(series)).getLenght();
}
/**
* Returns the x-value for an item within a series.
* <P>
* The implementation is responsible for ensuring that the x-values are
* presented in ascending order.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the x-value.
*/
public double getXValue(final int series, final int item) {
return new Double(((XYZSeries)this.seriesTable.get(series)).getX(item));
}
/**
* Returns the x-value for an item within a series.
* <P>
* The implementation is responsible for ensuring that the x-values are
* presented in ascending order.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the x-value.
*/
public Number getX(final int series, final int item) {
return ((XYZSeries)this.seriesTable.get(series)).getX(item);
}
/**
* Returns the y-value for an item within a series.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the y-value.
*/
public double getYValue(final int series, final int item) {
return new Double(((XYZSeries)this.seriesTable.get(series)).getY(item));
}
/**
* Returns the y-value for an item within a series.
* <P>
* The implementation is responsible for ensuring that the y-values are
* presented in ascending order.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the y-value.
*/
public Number getY(final int series, final int item) {
return ((XYZSeries)this.seriesTable.get(series)).getY(item);
}
/**
* Returns the z-value for the specified series and item.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the z-value for the specified series and item.
*/
public double getZValue(final int series, final int item) {
return new Double(((XYZSeries)this.seriesTable.get(series)).getZ(item));
}
/**
* Returns the z-value for an item within a series.
* <P>
* The implementation is responsible for ensuring that the z-values are
* presented in ascending order.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the z-value.
*/
public Number getZ(final int series, final int item) {
return ((XYZSeries)this.seriesTable.get(series)).getZ(item);
}
@Override
public Comparable getSeriesKey(int series) {
// TODO Auto-generated method stub
return null;
}
}
/*--------------------------------------------------------------------------------*/
/* XYZSeries.java */
package testchart;
import java.util.Vector;
public class XYZSeries {
/** The name of the serie. */
private String name;
/** The x values. */
private Vector xVal = new Vector();
/** The y values. */
private Vector yVal = new Vector();
/** The z values. */
private Vector zVal = new Vector();
public XYZSeries(String name) {
this.name = name;
}
/**
* This method add an XYZ coordinate to the serie.
*
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public void addData(double x, double y, double z) {
xVal.addElement(new Double(x));
yVal.addElement(new Double(y));
zVal.addElement(new Double(z));
}
/**
* This method clears all date added to the serie.
*
*/
public void clear() {
xVal.clear();
yVal.clear();
zVal.clear();
}
/**
*
* @return the name of the serie
*/
public String getName() {
return this.name;
}
public int getLenght() {
return xVal.size();
}
/**
*
* @param position (zero-based index)
* @return the value of the x coordinate
*/
public double getX(int position) {
return ((Double) xVal.get(position)).doubleValue();
}
/**
*
* @param position (zero-based index)
* @return the value of the y coordinate
*/
public double getY(int position) {
return ((Double) yVal.get(position)).doubleValue();
}
/**
*
* @param position (zero-based index)
* @return the value of the z coordinate
*/
public double getZ(int position) {
return ((Double) zVal.get(position)).doubleValue();
}
}