List of usage examples for org.jfree.chart.imagemap ImageMapUtilities writeImageMap
public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info) throws IOException
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartRenderedGraph.java
/** * {@inheritDoc}//ww w.java 2 s. c o m */ @Override public void writeImageMap(PrintWriter writer, String name) throws IOException { ImageMapUtilities.writeImageMap(writer, name, info); }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
public cfTagReturnType render(cfSession _Session) throws cfmRunTimeException { if ((storage == DB) && (!storageDBInit)) initDBStorage(_Session);// w w w . j av a 2 s. c o m try { JFreeChart chart = null; cfTag defaultChartTag = setDefaultParameters(_Session); // --[ Get the FORMAT property out byte format; String formatStr = getDynamic(_Session, "FORMAT").toString().toLowerCase(); if (formatStr.equals("jpg")) { format = FORMAT_JPG; } else if (formatStr.equals("png")) { format = FORMAT_PNG; } else { throw newBadFileException("Invalid FORMAT Attribute", "Only the jpg and png formats are supported."); } if (getConstant("STYLE") != null) throw newBadFileException("Attribute not supported", "The STYLE attribute is not supported. Use the DEFAULT attribute instead"); int height = getDynamic(_Session, "CHARTHEIGHT").getInt(); int width = getDynamic(_Session, "CHARTWIDTH").getInt(); String xAxisType = getDynamic(_Session, "XAXISTYPE").toString().toLowerCase(); cfCHARTInternalData data = new cfCHARTInternalData(xAxisType, defaultChartTag); _Session.setDataBin(DATA_BIN_KEY, data); // Render the CFCHARTSERIES tags renderToString(_Session); // Get the chart series List<cfCHARTSERIESData> series = data.getSeries(); if (series.size() == 0) throw newRunTimeException("You must specify at least one series"); String tipStyle = getDynamic(_Session, "TIPSTYLE").toString().toLowerCase(); String drillDownUrl = null; if (containsAttribute("URL")) drillDownUrl = getDynamic(_Session, "URL").toString(); String name = null; if (containsAttribute("NAME")) name = getDynamic(_Session, "NAME").toString(); // Check if this is a Pie or Ring chart boolean isPieOrRingChart = false; if (series.size() == 1) { cfCHARTSERIESData seriesData = series.get(0); if (seriesData.getType().equals("pie") || seriesData.getType().equals("ring")) { // Render the pie or ring chart chart = renderPieChart(_Session, data, series, tipStyle, drillDownUrl); isPieOrRingChart = true; } } if (!isPieOrRingChart) { // This must be a category chart so make sure none of the series are set // to Pie or Ring type // Also, if show3D is true then make sure there are only bar, line and // horizontalbar types boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean(); String seriesPlacement = getDynamic(_Session, "SERIESPLACEMENT").toString().toLowerCase(); if (!seriesPlacement.equals("default") && !seriesPlacement.equals("cluster") && !seriesPlacement.equals("stacked") && !seriesPlacement.equals("percent")) throw newRunTimeException( "The seriesPlacement value '" + seriesPlacement + "' is not supported"); if (bShow3D && seriesPlacement.equals("percent")) throw newRunTimeException( "The seriesPlacement value '" + seriesPlacement + "' is not supported in 3D charts"); boolean bCluster = true; if (seriesPlacement.equals("stacked") || seriesPlacement.equals("percent")) bCluster = false; if (series.size() > 1) { for (int i = 0; i < series.size(); i++) { cfCHARTSERIESData seriesData = series.get(i); if (seriesData.getType().equals("pie") || seriesData.getType().equals("ring")) throw newRunTimeException( "A chart can only have 1 series when a pie or ring series is specified"); if (bShow3D && !seriesData.getType().equals("bar") && !seriesData.getType().equals("line") && !seriesData.getType().equals("horizontalbar")) throw newRunTimeException( "Only bar, line, horizontal bar and pie charts can be displayed in 3D"); if (!bCluster && !seriesData.getType().equals("bar") && !seriesData.getType().equals("horizontalbar")) throw newRunTimeException("The seriesPlacement value '" + seriesPlacement + "' is only supported in bar and horizontal bar charts"); } } int seriesDataType = series.get(0).getSeriesDataType(); // Render the scale(xy) or category chart // This is overriding the type from the cfchart variable as it is // determined // by the series data. if (seriesDataType == cfCHARTSERIESData.CATEGORY_SERIES) { chart = renderCategoryChart(_Session, data, tipStyle, drillDownUrl, seriesPlacement, height); } else { chart = renderXYChart(_Session, data, tipStyle, drillDownUrl, seriesPlacement, height); } } // Output the chart try { ChartRenderingInfo info = null; if ((drillDownUrl != null) || (!tipStyle.equals("none"))) info = new ChartRenderingInfo(new StandardEntityCollection()); if (name != null) { // Generate the chart and save the contents in the name variable byte[] chartBytes = generateChart(chart, format, width, height, info); _Session.setData(name, new cfBinaryData(chartBytes)); } else { // Return the chart to the browser String path = null; if (containsAttribute("PATH")) path = getDynamic(_Session, "PATH").toString(); String filename = saveChart(_Session, chart, format, width, height, info); String chartUrl = generateChartUrl(_Session, filename, path); if (info == null) { _Session.write("<img src=\"" + chartUrl + "\" width=\"" + width + "\" height=\"" + height + "\" />"); } else { ImageMapUtilities.writeImageMap(_Session.RES.getWriter(), filename, info); _Session.write("<img src=\"" + chartUrl + "\" width=\"" + width + "\" height=\"" + height + "\" usemap=\"#" + filename + "\" border=\"0\"/>"); } } } catch (IOException ioe) { throw newRunTimeException("Failed to generate chart - " + ioe.toString()); } } finally { _Session.deleteDataBin(DATA_BIN_KEY); } return cfTagReturnType.NORMAL; }