List of usage examples for org.jfree.chart.urls StandardCategoryURLGenerator StandardCategoryURLGenerator
public StandardCategoryURLGenerator(String prefix)
From source file:org.jfree.chart.demo.ImageMapDemo4.java
/** * Starting point for the demo./*from w w w. ja va 2s.com*/ * * @param args ignored. */ public static void main(final String[] args) { // create a chart final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 }, { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 }, { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); JFreeChart chart = null; final boolean drilldown = true; if (drilldown) { final CategoryAxis3D categoryAxis = new CategoryAxis3D("Category"); final ValueAxis valueAxis = new NumberAxis3D("Value"); final BarRenderer3D renderer = new BarRenderer3D(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createBarChart3D("Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, 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("barchart101.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("barchart101.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=\"barchart100.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()); } }
From source file:org.jfree.chart.demo.ImageMapDemo1.java
/** * Starting point for the demo.// w w w .j a v a2 s. c o m * * @param args ignored. */ public static void main(final String[] args) { // create a chart final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 }, { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 }, { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); JFreeChart chart = null; final boolean drilldown = true; if (drilldown) { final CategoryAxis categoryAxis = new CategoryAxis("Category"); final ValueAxis valueAxis = new NumberAxis("Value"); final BarRenderer renderer = new BarRenderer(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createBarChart("Vertical Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, 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("barchart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("barchart100.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=\"barchart100.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()); } }
From source file:org.pentaho.chart.plugin.jfreechart.utils.JFreeChartUtils.java
/** * @param renderer - Renderer for the current chart * @param chartDocument - ChartDocument that defines what the series should look like *//*w ww .j a va 2s.c o m*/ public static void setURLGeneration(final CategoryItemRenderer renderer, final ChartDocument chartDocument) { if (JFreeChartUtils.getShowUrls(chartDocument)) { final String URLPrefix = JFreeChartUtils.getURLText(chartDocument); renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(URLPrefix)); } }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) { JFreeChart chart = null;/*from www . ja v a 2s .c o m*/ PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation()); CategoryDataset dataset = (CategoryDataset) chartData.getDatasource(); String type = chartData.getType(); String xAxis = chartData.getXlabel(); String yAxis = chartData.getYlabel(); boolean is3d = chartData.isChart3d(); boolean legend = chartData.isLegend(); if (type.equalsIgnoreCase("bar")) { if (is3d == true) { chart = ChartFactory.createBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else { chart = ChartFactory.createBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } setBarOutline(chart, chartData); } else if (type.equalsIgnoreCase("stackedbar")) { if (is3d == true) { chart = ChartFactory.createStackedBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else { chart = ChartFactory.createStackedBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } setBarOutline(chart, chartData); } else if (type.equalsIgnoreCase("line")) { if (is3d == true) chart = ChartFactory.createLineChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); else chart = ChartFactory.createLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("area")) { chart = ChartFactory.createAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("stackedarea")) { chart = ChartFactory.createStackedAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("waterfall")) { chart = ChartFactory.createWaterfallChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("gantt")) { chart = ChartFactory.createGanttChart("", xAxis, yAxis, (IntervalCategoryDataset) dataset, legend, true, false); } CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot(); plot.setDomainGridlinesVisible(chartData.isDomainGridLines()); plot.setRangeGridlinesVisible(chartData.isRangeGridLines()); if (chartData.getGenerateMap() != null) plot.getRenderer().setBaseItemURLGenerator(new StandardCategoryURLGenerator("")); int seriesCount = plot.getDataset().getColumnCount(); if (chartData.getLineStokeWidth() > 0) { for (int index = 0; index <= seriesCount; index++) plot.getRenderer().setSeriesStroke(index, new BasicStroke(chartData.getLineStokeWidth())); } setCategorySeriesColors(chart, chartData); setCategoryExtensions(chart, chartData); return chart; }
From source file:org.toobsframework.pres.chart.ChartBuilder.java
private Plot configurePlot(IRequest componentRequest, String id, BasePlot plotDef, Map params, boolean isSubPlot, int parentPlotType, BasePlot parentPlot) throws ChartException { boolean is3D = (ParameterUtil.resolveParam(componentRequest, plotDef.getIs3D(), params, "false")[0] .equals("false") ? false : true); Integer plotType = ChartUtil.getSupportedPlots() .get(ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]); if (plotType == null) { throw new ChartException("Unsupported Plot type " + ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]); }/*from w w w .j a v a 2s .com*/ Plot plot = null; switch (plotType) { case ChartUtil.PLOT_CATEGORY_TYPE: DomainAxisDef domainAxis = null; RangeAxisDef rangeAxis = null; plot = new CategoryPlot(); if (isSubPlot) { if (plotDef.getDomainAxisDef() != null && parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) { domainAxis = plotDef.getDomainAxisDef(); } else if (parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) { domainAxis = parentPlot.getDomainAxisDef(); } if (plotDef.getRangeAxisDef() != null && parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) { rangeAxis = plotDef.getRangeAxisDef(); } else if (parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) { rangeAxis = parentPlot.getRangeAxisDef(); } } else { domainAxis = plotDef.getDomainAxisDef(); rangeAxis = plotDef.getRangeAxisDef(); } ((CategoryPlot) plot) .setDomainAxis(ChartUtil.createCategoryAxis(componentRequest, domainAxis, params, is3D)); ((CategoryPlot) plot).setRangeAxis(createValueAxis(componentRequest, rangeAxis, params, is3D)); for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) { org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g); CategoryItemRenderer renderer = (CategoryItemRenderer) ChartUtil.getRenderer(componentRequest, plotDef, group, params); if (group.getUrlBase() != null) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase())); } ((CategoryPlot) plot).setRenderer(g, renderer); DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset(); if (group.getId() != null) { DatasetGroup datasetGroup = new DatasetGroup(group.getId()); categoryDataset.setGroup(datasetGroup); } for (int i = 0; i < group.getDatasetCount(); i++) { Dataset dataset = group.getDataset(i); generateCategoryDataset(componentRequest, id, categoryDataset, dataset, params); this.setValueAxisBounds(componentRequest, ((CategoryPlot) plot).getRangeAxis(), rangeAxis, params); } ((CategoryPlot) plot).setDataset(g, categoryDataset); } ChartUtil.configurePlot(componentRequest, plot, plotDef, domainAxis, rangeAxis, params); break; case ChartUtil.PLOT_XY_TYPE: plot = new XYPlot(); break; case ChartUtil.PLOT_SPIDER_TYPE: plot = new SpiderWebPlot(); DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset(); for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) { org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g); if (group.getUrlBase() != null) { ((SpiderWebPlot) plot).setURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase())); } if (group.getId() != null) { DatasetGroup datasetGroup = new DatasetGroup(group.getId()); categoryDataset.setGroup(datasetGroup); } for (int i = 0; i < group.getDatasetCount(); i++) { Dataset dataset = group.getDataset(i); //generateCategoryDataset(id, categoryDataset, dataset, params); for (int s = 0; s < dataset.getDatasetSeriesCount(); s++) { DatasetSeries series = dataset.getDatasetSeries(s); if (series.getColor() != null) { ((SpiderWebPlot) plot).setSeriesPaint(i + s, ChartUtil.getColor(series.getColor())); } } } } ((SpiderWebPlot) plot).setDataset(categoryDataset); ChartUtil.configurePlot(componentRequest, plot, plotDef, null, null, params); break; } return plot; }