List of usage examples for org.jfree.chart.renderer.category BarRenderer3D setToolTipGenerator
@Override public void setToolTipGenerator(CategoryToolTipGenerator generator)
From source file:org.jfree.chart.demo.ImageMapDemo4.java
/** * Starting point for the demo.//from w w w. j ava2 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 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:com.tonbeller.jpivot.chart.ChartFactory.java
/** * Creates a vertical 3D-effect bar chart with default settings. * * @param title the chart title./*from w ww.j a v a 2s. co m*/ * @param categoryAxisLabel the label for the category axis. * @param valueAxisLabel the label for the value axis. * @param data the dataset for the chart. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return a vertical 3D-effect bar chart. */ public static JFreeChart createBarChart3D(String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); BarRenderer3D renderer = new BarRenderer3D(); //renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); if (tooltips) { renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); plot.setForegroundAlpha(0.75f); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:com.sun.japex.ChartGenerator.java
private JFreeChart generateDriverBarChart() { try {//from ww w .java 2 s .co m String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X); // Ensure japex.resultUnitX is not null if (resultUnitX == null) { resultUnitX = ""; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset datasetX = new DefaultCategoryDataset(); // Find first normalizer driver (if any) and adjust unit DriverImpl normalizerDriver = null; for (DriverImpl driver : _testSuite.getDriverInfoList()) { if (driver.isNormal()) { normalizerDriver = driver; break; } } // Check if normalizer driver can be used as such if (normalizerDriver != null) { if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) { System.out.println("Warning: Driver '" + normalizerDriver.getName() + "' cannot be used to normalize results"); normalizerDriver = null; } else { resultUnit = "% of " + resultUnit; if (resultUnitX != null) { resultUnitX = "% of " + resultUnitX; } } } boolean hasValueX = false; // Generate charts for (DriverImpl di : _testSuite.getDriverInfoList()) { if (normalizerDriver != null) { dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)), di.getName(), "Arithmetic Mean"); dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)), di.getName(), "Geometric Mean"); dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)), di.getName(), "Harmonic Mean"); if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) { datasetX.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X) / normalizerDriver .getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X)), di.getName(), "Arithmetic Mean"); datasetX.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X) / normalizerDriver .getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X)), di.getName(), "Geometric Mean"); datasetX.addValue( (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X)), di.getName(), "Harmonic Mean"); hasValueX = true; } } else { dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN), di.getName(), "Arithmetic Mean"); dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN), di.getName(), "Geometric Mean"); dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN), di.getName(), "Harmonic Mean"); if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) { datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X), di.getName(), "Arithmetic Mean"); datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X), di.getName(), "Geometric Mean"); datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X), di.getName(), "Harmonic Mean"); hasValueX = true; } } } int nextPlotIndex = 1; CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); // Use same renderer in combine charts to get same colors BarRenderer3D renderer = new BarRenderer3D(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); // Bar chart for secondary data set based on japex.resultValueX if (hasValueX) { NumberAxis rangeAxisX = new NumberAxis(resultUnitX); CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer); // Set transparency and clear legend for this plot subplotX.setForegroundAlpha(0.7f); subplotX.setFixedLegendItems(new LegendItemCollection()); plot.add(subplotX, nextPlotIndex++); _chartHeight += 50; // Adjust chart height } else { } // Bar chart for main data set based on japex.resultValue NumberAxis rangeAxis = new NumberAxis(resultUnit); CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer); subplot.setForegroundAlpha(0.7f); // transparency plot.add(subplot, nextPlotIndex); // Create chart and save it as JPEG String chartTitle = "Result Summary"; JFreeChart chart = new JFreeChart(hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"), new Font("SansSerif", Font.BOLD, 14), plot, true); chart.setAntiAlias(true); return chart; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.sun.japex.ChartGenerator.java
private int generateTestCaseBarCharts(String baseName, String extension) { int nOfFiles = 0; List<DriverImpl> driverInfoList = _testSuite.getDriverInfoList(); // Get number of tests from first driver final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size(); int groupSizesIndex = 0; int[] groupSizes = calculateGroupSizes(nOfTests, _plotGroupSize); try {//from www .j a v a 2 s . c om String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X); // Ensure japex.resultUnitX is not null if (resultUnitX == null) { resultUnitX = ""; } // Find first normalizer driver (if any) DriverImpl normalizerDriver = null; for (DriverImpl di : driverInfoList) { if (di.isNormal()) { normalizerDriver = di; break; } } // Check if normalizer driver can be used as such if (normalizerDriver != null) { if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) { normalizerDriver = null; } else { resultUnit = "% of " + resultUnit; if (resultUnitX != null) { resultUnitX = "% of " + resultUnitX; } } } // Generate charts DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset datasetX = new DefaultCategoryDataset(); boolean hasValueX = false; int i = 0, thisGroupSize = 0; for (; i < nOfTests; i++) { for (DriverImpl di : driverInfoList) { TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(i); // User normalizer driver if defined if (normalizerDriver != null) { TestCaseImpl normalTc = (TestCaseImpl) normalizerDriver.getAggregateTestCases().get(i); dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * tc.getDoubleParamNoNaN(Constants.RESULT_VALUE) / normalTc.getDoubleParamNoNaN(Constants.RESULT_VALUE)), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); if (tc.hasParam(Constants.RESULT_VALUE_X)) { datasetX.addValue( (100.0 * tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X) / normalTc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X)), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); hasValueX = true; } } else { dataset.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); if (tc.hasParam(Constants.RESULT_VALUE_X)) { datasetX.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); hasValueX = true; } } } thisGroupSize++; // Generate chart for this group if complete if (thisGroupSize == groupSizes[groupSizesIndex]) { int nextPlotIndex = 1; CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); // Use same renderer in combine charts to get same colors BarRenderer3D renderer = new BarRenderer3D(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); // Bar chart for secondary data set based on japex.resultValueX if (hasValueX) { NumberAxis rangeAxisX = new NumberAxis(resultUnitX); CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer); // Set transparency and clear legend for this plot subplotX.setForegroundAlpha(0.7f); subplotX.setFixedLegendItems(new LegendItemCollection()); plot.add(subplotX, nextPlotIndex++); _chartHeight += 50; // Adjust chart height } // Bar chart for main data set based on japex.resultValue NumberAxis rangeAxis = new NumberAxis(resultUnit); CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer); subplot.setForegroundAlpha(0.7f); // transparency plot.add(subplot, nextPlotIndex); // Create chart and save it as JPEG String chartTitle = _plotDrivers ? "Results per Driver" : "Results per Test"; JFreeChart chart = new JFreeChart( hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"), new Font("SansSerif", Font.BOLD, 14), plot, true); chart.setAntiAlias(true); ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension), chart, _chartWidth, _chartHeight); nOfFiles++; groupSizesIndex++; thisGroupSize = 0; // Create fresh data sets dataset = new DefaultCategoryDataset(); datasetX = new DefaultCategoryDataset(); } } } catch (RuntimeException e) { throw e; } catch (Exception e) { e.printStackTrace(); } return nOfFiles; }