List of usage examples for org.jfree.chart.urls StandardXYURLGenerator StandardXYURLGenerator
public StandardXYURLGenerator(String prefix)
From source file:org.jfree.chart.demo.ImageMapDemo3.java
/** * Starting point for the demo./*from w w w . ja v a2s.co m*/ * * @param args ignored. * * @throws ParseException if there is a problem parsing dates. */ public static void main(final String[] args) throws ParseException { // Create a sample dataset final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); final XYSeries dataSeries = new XYSeries("Curve data"); final ArrayList toolTips = new ArrayList(); dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22); toolTips.add("1D - 5.22"); dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18); toolTips.add("2D - 5.18"); dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23); toolTips.add("3D - 5.23"); dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15); toolTips.add("4D - 5.15"); dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22); toolTips.add("5D - 5.22"); dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25); toolTips.add("6D - 5.25"); dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31); toolTips.add("7D - 5.31"); dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36); toolTips.add("8D - 5.36"); final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries); final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator(); ttg.addToolTipSeries(toolTips); // Create the chart final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp"); final ValueAxis timeAxis = new DateAxis(""); final NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null); final StandardXYItemRenderer sxyir = new StandardXYItemRenderer( StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg); sxyir.setShapesFilled(true); plot.setRenderer(sxyir); final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("xychart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("xychart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"xychart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } return; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static JFreeChart createChartWithXYDataSet(ChartData chartData) { XYDataset dataset = (XYDataset) chartData.getDatasource(); String type = chartData.getType(); String xAxis = chartData.getXlabel(); String yAxis = chartData.getYlabel(); boolean legend = chartData.isLegend(); JFreeChart chart = null;//from w w w . j a va 2 s . co m PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation()); if (type.equalsIgnoreCase("timeseries")) { chart = ChartFactory.createTimeSeriesChart("", xAxis, yAxis, dataset, legend, true, false); } else if (type.equalsIgnoreCase("xyline")) { chart = ChartFactory.createXYLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("polar")) { chart = ChartFactory.createPolarChart("", dataset, legend, true, false); } else if (type.equalsIgnoreCase("scatter")) { chart = ChartFactory.createScatterPlot("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("xyarea")) { chart = ChartFactory.createXYAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("xysteparea")) { chart = ChartFactory.createXYStepAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("xystep")) { chart = ChartFactory.createXYStepChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("bubble")) { chart = ChartFactory.createBubbleChart("", xAxis, yAxis, (XYZDataset) dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("candlestick")) { chart = ChartFactory.createCandlestickChart("", xAxis, yAxis, (OHLCDataset) dataset, legend); } else if (type.equalsIgnoreCase("boxandwhisker")) { chart = ChartFactory.createBoxAndWhiskerChart("", xAxis, yAxis, (BoxAndWhiskerXYDataset) dataset, legend); } else if (type.equalsIgnoreCase("highlow")) { chart = ChartFactory.createHighLowChart("", xAxis, yAxis, (OHLCDataset) dataset, legend); } else if (type.equalsIgnoreCase("histogram")) { chart = ChartFactory.createHistogram("", xAxis, yAxis, (IntervalXYDataset) dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("wind")) { chart = ChartFactory.createWindPlot("", xAxis, yAxis, (WindDataset) dataset, legend, true, false); } if (chart.getPlot() instanceof XYPlot) { chart.getXYPlot().setDomainGridlinesVisible(chartData.isDomainGridLines()); chart.getXYPlot().setRangeGridlinesVisible(chartData.isRangeGridLines()); if (chartData.getGenerateMap() != null) chart.getXYPlot().getRenderer().setURLGenerator(new StandardXYURLGenerator("")); } setXYSeriesColors(chart, chartData); setXYExtensions(chart, chartData); return chart; }