Example usage for org.jfree.chart ChartUtilities writeImageMap

List of usage examples for org.jfree.chart ChartUtilities writeImageMap

Introduction

In this page you can find the example usage for org.jfree.chart ChartUtilities writeImageMap.

Prototype

public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info,
        boolean useOverLibForToolTips) throws IOException 

Source Link

Document

Writes an image map to an output stream.

Usage

From source file:org.posterita.core.AbstractChart.java

public String getImageMap(String imageMapName) throws OperationException {
    try {/*from   www . j  ava 2 s. co m*/
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        ChartUtilities.writeImageMap(printWriter, imageMapName, renderingInfo, false);
        printWriter.flush();

        String imageMap = stringWriter.getBuffer().toString();
        return imageMap;
    } catch (IOException e) {
        throw new OperationException("Problem occured while writing imagemap", e);
    }
}

From source file:org.posterita.core.AbstractChart.java

public void writeImageMap(OutputStream outputStream, String imageMapName) throws OperationException {
    PrintWriter printWriter = new PrintWriter(outputStream);
    try {//  w w  w .  j  av  a  2s .  c om
        ChartUtilities.writeImageMap(printWriter, imageMapName, renderingInfo, false);
        printWriter.flush();
        printWriter.close();
    } catch (IOException e) {
        throw new OperationException("Problem occured while writing imagemap", e);
    }
}

From source file:org.posterita.core.AbstractChart.java

public String saveImageMap(String imageMapPath) throws OperationException {
    String fileSeparator = System.getProperty("file.separator");
    int index = imageMapPath.lastIndexOf(fileSeparator) + 1;
    String imageMapName = imageMapPath.substring(index);

    try {/*from  ww  w.  ja  va 2s . c om*/
        FileOutputStream fos = new FileOutputStream(new File(imageMapPath));
        PrintWriter printWriter = new PrintWriter(fos);
        ChartUtilities.writeImageMap(printWriter, imageMapName, renderingInfo, false);
        printWriter.flush();
        fos.close();

        return imageMapName;
    } catch (IOException e) {
        throw new OperationException("Problem occured while writing imagemap", e);
    }
}

From source file:org.matsim.counts.algorithms.graphs.helper.OutputDelegate.java

private void writeHtml(final CountsGraph cg, final String iter_path, boolean indexFile) {
    /* we want landscape, thus exchange width / height */
    int width = 800;
    int height = 600;

    JFreeChart chart = null;/*www.j  a  v a 2 s.c  om*/
    String fileName = "";
    File file2;
    if (!indexFile) {
        chart = cg.getChart();
        fileName = cg.getFilename();
        file2 = new File(iter_path + "/" + fileName + ".html");
    } else {
        file2 = new File(iter_path + "/start.html");
    }

    PrintWriter writer = null;
    try {
        ChartRenderingInfo info = null;
        File file1;
        if (!indexFile) {
            info = new ChartRenderingInfo(new StandardEntityCollection());
            file1 = new File(iter_path + "/png/" + fileName + ".png");
            ChartUtilities.saveChartAsPNG(file1, chart, width, height, info);
        }

        writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file2)));

        writer.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        //writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
        writer.println(
                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
        writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">");
        writer.println("<head>");
        //writer.println("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />");
        writer.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
        writer.println("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\"/>");
        writer.println("<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"/>");

        writer.println("<title> MATSim validation </title>");
        writer.println("<script type=\"text/javascript\" src=\"div/overlib.js\"></script>");
        writer.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"div/style1.css\"/>");
        writer.println("</head>");
        writer.println("<body>");

        writer.println("<div id=\"overDiv\" style=\"Z-INDEX: 1; POSITION: absolute\"></div>");

        writer.println("<div id=\"header\">");
        writer.println("<div id=\"logo\">");
        writer.println(
                "<img src=\"div/logo.png\" width=\"224\" height=\"52\" style=\"border:none;\" alt=\"logo\"/><br>Multi-Agent Transport Simulation Toolkit");
        writer.println("</div>");
        writer.println("<h3>Counting Volumes</h3>");
        writer.println("</div>");

        writer.println("<div id=\"footer\">");

        GregorianCalendar cal = new GregorianCalendar();
        writer.println(cal.get(Calendar.DATE) + ".");
        writer.println(cal.get(Calendar.MONTH) + 1 + ".");
        writer.println(cal.get(Calendar.YEAR) + "\t ");
        writer.println(System.getProperty("user.name"));

        writer.println("</div>");
        writer.println("<div id=\"links\">");

        for (Section sec : this.sections_) {
            writer.print("<h3>");
            writer.print(sec.getTitle() + ":<br />");
            writer.print("</h3>");

            Iterator<MyURL> url_it = sec.getURLs().iterator();
            while (url_it.hasNext()) {
                MyURL url = url_it.next();
                writer.println("<a href=\"" + url.address + "\">" + url.displayText + "</a><br />");
            }
        }
        writer.println("</div>");

        writer.println("<div id=\"contents\">");
        writer.println("<p>");
        if (!indexFile) {
            ChartUtilities.writeImageMap(writer, "chart", info, true);

            /*
              chart=cg.getChart();
              CategoryPlot plot=chart.getCategoryPlot();
            Renderer renderer=(BarRenderer) plot.getRenderer();
            renderer.getSeriesToolTipGenerator(0);
             */

            /*   how to get tooltips in there, without using xxxToolTipTagFragmentGenerator?
                 Wait for next version of jFreeChart? Meanwhile doing slight changes to the libarary
                 String imagemap=ChartUtilities.getImageMap("chart", info);
                 System.out.println(imagemap);
             */

            // reference '#chart' not working without '#'
            writer.println("<img src=\"png/" + fileName + ".png\" " + "width=\"" + width + "\" height=\""
                    + height + "\" style=\"border:none;\" alt=\"graph\" usemap=\"#chart\"/>");
        } else {
            writer.println("<img src=\"div/title.png\" "
                    + "width=\"972\" height=\"602\" style=\"border:none;\" alt=\"title\"/>");
        }
        writer.println("</p>");
        writer.println("</div>");
        writer.println("</body>");
        writer.println("</html>");

    } catch (IOException e) {
        System.out.println(e.toString());
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

/**
 * Create a PNG image file from a JFreeChart object
 * /*from   w w w  .ja  va2  s .c  o  m*/
 * @param chart
 *          The chart object to create an image from
 * @param path
 *          The path and name of the image file to create
 * @param width
 *          The width of the image in pixels
 * @param height
 *          The height of the image in pixels
 * @param writer
 *          A writer for the iamge map to be written to
 * @throws IOException
 */
private static void saveChartAsPNG(final JFreeChart chart, final String path, final int width, final int height,
        final PrintWriter writer, final ChartRenderingInfo info) throws IOException {
    File file = new File(path + ".png"); //$NON-NLS-1$
    ChartUtilities.saveChartAsPNG(file, chart, width, height, info);

    // TODO support tool tip generators

    // TODO support URL fragment generators

    // TODO: make the image map name unique on the page
    if (writer != null) {
        ChartUtilities.writeImageMap(writer, "map-name", info, true); //$NON-NLS-1$
    }
}