List of usage examples for org.jfree.chart ChartFactory createBarChart
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:weka.core.ChartUtils.java
/** * Create a histogram chart from summary data (i.e. a list of bin labels and * corresponding frequencies)//from w ww . j a v a 2 s . c o m * * @param bins a list of bin labels * @param freqs the corresponding frequencies of the bins * @param additionalArgs optional arguments to the renderer (may be null) * @return a histogram chart * @throws Exception if a problem occurs */ protected static JFreeChart getHistogramFromSummaryDataChart(List<String> bins, List<Double> freqs, List<String> additionalArgs) throws Exception { if (bins.size() != freqs.size()) { throw new Exception("Number of bins should be equal to number of frequencies!"); } String plotTitle = "Histogram"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String xLabel = getOption(additionalArgs, "-x-label"); xLabel = xLabel == null ? "" : xLabel; String yLabel = getOption(additionalArgs, "-y-label"); yLabel = yLabel == null ? "" : yLabel; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String seriesTitle = ""; for (int i = 0; i < bins.size(); i++) { String binLabel = bins.get(i); Number freq = freqs.get(i); dataset.addValue(freq, seriesTitle, binLabel); } JFreeChart chart = null; chart = ChartFactory.createBarChart(plotTitle, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(java.awt.Color.white); chart.setTitle(new TextTitle(plotTitle, new Font("SansSerif", Font.BOLD, 12))); return chart; }
From source file:control.JGeraGraficos.java
public void PrintGraficoSegundoExemplo() { String valorJava = getValorArquivoTxt("c:\\AppsPrjFinal\\ESTOUROJVMJAVA.txt"); String valorJavaThRead = getValorArquivoTxt("c:\\AppsPrjFinal\\ESTOUROJVMJAVATHREAD.txt"); String valorJOCL = getValorArquivoTxt("c:\\AppsPrjFinal\\ESTOUROJVMJOCL.txt"); if (valorJava.isEmpty()) { JOptionPane.showMessageDialog(new JPanel(), "Processo Java No Executado", "Executar Processo", JOptionPane.INFORMATION_MESSAGE); } else if (valorJavaThRead.isEmpty()) { JOptionPane.showMessageDialog(new JPanel(), "Processo Java ThRead No Executado", "Executar Processo", JOptionPane.INFORMATION_MESSAGE); } else if (valorJOCL.isEmpty()) { JOptionPane.showMessageDialog(new JPanel(), "Processo JOCL No Executado", "Executar Processo", JOptionPane.INFORMATION_MESSAGE); } else {/* ww w. ja va 2 s. c om*/ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.clear(); dataset.addValue(Float.parseFloat(valorJava), "Java", "Java"); dataset.addValue(Float.parseFloat(valorJavaThRead), "Java ThRead", "Java ThRead"); dataset.addValue(Float.parseFloat(valorJOCL), "JOCL", "JOCL"); JFreeChart chart = ChartFactory.createBarChart("Grafio de Performance", null, "Tempo(ms)", dataset, PlotOrientation.VERTICAL, true, true, true); ChartFrame frame = new ChartFrame("Grafio de Performance", chart); frame.setBounds(300, 78, 800, 620); frame.setVisible(true); } }
From source file:org.tap4j.plugin.util.GraphHelper.java
/** * Creates the graph displayed on Method results page to compare execution * duration and status of a test method across builds. * // w w w.j a v a 2 s . c o m * At max, 9 older builds are displayed. * * @param req * request * @param dataset * data set to be displayed on the graph * @param statusMap * a map with build as key and the test methods execution status * (result) as the value * @param methodUrl * URL to get to the method from a build test result page * @return the chart */ public static JFreeChart createMethodChart(StaplerRequest req, final CategoryDataset dataset, final Map<NumberOnlyBuildLabel, String> statusMap, final String methodUrl) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart // title null, // unused " Duration (secs)", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips true // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.removeLegend(); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer br = new BarRenderer() { private static final long serialVersionUID = 961671076462240008L; Map<String, Paint> statusPaintMap = new HashMap<String, Paint>(); { statusPaintMap.put("PASS", ColorPalette.BLUE); statusPaintMap.put("SKIP", ColorPalette.YELLOW); statusPaintMap.put("FAIL", ColorPalette.RED); } /** * Returns the paint for an item. Overrides the default behavior * inherited from AbstractSeriesRenderer. * * @param row * the series. * @param column * the category. * * @return The item color. */ public Paint getItemPaint(final int row, final int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); Paint paint = statusPaintMap.get(statusMap.get(label)); // when the status of test method is unknown, use gray color return paint == null ? Color.gray : paint; } }; br.setBaseToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); if ("UNKNOWN".equals(statusMap.get(label))) { return "unknown"; } // values are in seconds return dataset.getValue(row, column) + " secs"; } }); br.setBaseItemURLGenerator(new CategoryURLGenerator() { public String generateURL(CategoryDataset dataset, int series, int category) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(category); if ("UNKNOWN".equals(statusMap.get(label))) { // no link when method result doesn't exist return null; } // return label.build.getUpUrl() + label.build.getNumber() + "/" + PluginImpl.URL + "/" + methodUrl; return label.build.getUpUrl() + label.build.getNumber() + "/tap/" + methodUrl; } }); br.setItemMargin(0.0); br.setMinimumBarLength(5); // set the base to be 1/100th of the maximum value displayed in the // graph br.setBase(br.findRangeBounds(dataset).getUpperBound() / 100); plot.setRenderer(br); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:com.argeloji.server.BarChartDemo4.java
/** * Creates a sample chart./* w w w.j a v a 2s . com*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Cevap Dalm", // chart title "Seenekler", // domain axis label "renci Says", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(new Color(0xFFFFFF)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); //renderer.setMaxBarWidth(0.10); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GREEN); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED); final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp3); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:grafici.MediciBarChart.java
/** * Creates a sample chart.//from w ww . j a v a 2s . c o m * * @param dataset * the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(titolo, // chart // title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:UserInterface.DoctorRole.DoctorReportChartJPanel.java
private void level1jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_level1jButton1ActionPerformed // TODO add your handling code here: ReportToReporter report = enterprise.getReport(); if (report.getStatus() != null) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(report.getIncidentnumber(), "Incident", "Incident"); dataset.addValue(report.getNearmissnumber(), "Near miss", "Near miss"); dataset.addValue(report.getUnsafenumber(), "Unsafe condition", "Unsafe condition"); JFreeChart chart = ChartFactory.createBarChart("Level1 Error", "Error Name", "Times", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.DARK_GRAY); ChartFrame frame = new ChartFrame("Chart for ERROR", chart); frame.setVisible(true);//from ww w .ja va 2 s . c o m frame.setSize(350, 450); } else { JOptionPane.showMessageDialog(null, "Sorry, the final report has not been generated"); } // report.getMaxlevel1() = maxlevel1number; }
From source file:ReportGen.java
private void yearlyPreview() throws NumberFormatException { exportcounttableexcel.setEnabled(true); exportcounttablepdf.setEnabled(true); tableModel = (DefaultTableModel) dataTable.getModel(); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged();//from ww w . j ava2 s . c o m String str[] = { "Years", "Values" }; tableModel.setColumnIdentifiers(str); ChartPanel chartPanel; displaypane.removeAll(); displaypane.revalidate(); displaypane.repaint(); displaypane.setLayout(new BorderLayout()); //row String series1 = "Results"; //column String year[] = { "2014", "2015", "2016", "2017", "2018", "2019", "2020" }; dataset = new DefaultCategoryDataset(); dataset.addValue(0, series1, year[0]); dataset.addValue(1, series1, year[1]); dataset.addValue(2, series1, year[2]); dataset.addValue(3, series1, year[3]); dataset.addValue(4, series1, year[4]); dataset.addValue(5, series1, year[5]); dataset.addValue(6, series1, year[6]); chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title "Years", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chartPanel = new ChartPanel(chart); displaypane.add(chartPanel, BorderLayout.CENTER); }
From source file:br.com.OCTur.view.GraficoController.java
private void produtosMaisAntigos() { DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); for (EntidadeGrafico<Produto> entidadeGrafico : produto) { if (entidadeGrafico.getValue() >= slMeta.getValue()) { dcdDados.addValue(entidadeGrafico.getValue(), "Dias/Acima do esperado", entidadeGrafico.toString()); } else {/* ww w. ja va 2 s. com*/ dcdDados.addValue(entidadeGrafico.getValue(), "Dias", entidadeGrafico.toString()); } } JFreeChart jFreeChart = ChartFactory.createBarChart(ControlTranducao.traduzirPalavra("PRODUTOSMAISANTIGOS"), "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false); jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{0}", NumberFormat.getCurrencyInstance())); jFreeChart.getCategoryPlot() .addRangeMarker(new ValueMarker(slMeta.getValue(), Color.CYAN, new BasicStroke(1.0f))); ChartPanel chartPanel = new ChartPanel(jFreeChart); snProdutosMaisAntigos.setContent(chartPanel); }
From source file:result.analysis.Chart.java
void avgMarks(String batch, String sem, String[] colleges) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (String college : colleges) { db = mongoClient.getDB(college); analyz = new Analyze(db); String collection_name = "cs_" + batch + "_" + sem + "_sem"; DBCollection collection = db.getCollection(collection_name); String[] codes = analyz.GetSubCodes(collection); for (String code : codes) { double avg = analyz.GetAverageSubject(collection, code); dataset.setValue(avg, college, code); }/*w w w. j av a 2 s . co m*/ } JFreeChart barChart = ChartFactory.createBarChart("Average in each subject", "SUBJECT", "AVERAGE MARKS", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = barChart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); // set the color (r,g,b) or (r,g,b,a) Color color = new Color(79, 129, 189); renderer.setSeriesPaint(0, color); ChartFrame frame = new ChartFrame( "Subject-wise average marks of 20" + batch + " batch " + sem + "th semester", barChart); frame.setVisible(true); frame.setSize(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height); save_jpeg(barChart); }
From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java
/** * @param adapter// w w w . ja v a 2s. c om * @param annotations * @return */ private static JFreeChart createChart(final AbstractChart adapter, final List<XYAnnotation> annotations) { final JFreeChart chart; if (adapter.getItems() instanceof XYDataset) { chart = ChartFactory.createTimeSeriesChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(), (XYDataset) adapter.getItems(), true, false, false); final ValueAxis domainAxis = new DateAxis(); domainAxis.setLabelFont(LABEL_FONT); domainAxis.setTickLabelFont(LABEL_FONT); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); chart.getXYPlot().setDomainAxis(domainAxis); chart.getXYPlot().getRangeAxis().setLabelFont(LABEL_FONT); chart.getXYPlot().getRangeAxis().setTickLabelFont(LABEL_FONT); chart.getXYPlot().getRangeAxis().setStandardTickUnits(adapter.getRangeTickUnits()); if (adapter.isAlwaysScaleFromZero()) { final double upperBound = chart.getXYPlot().getRangeAxis().getRange().getUpperBound(); final Range range = new Range(0, upperBound + (upperBound * 0.2)); chart.getXYPlot().getRangeAxis().setRange(range); } for (Marker marker : adapter.getMarkers()) { chart.getXYPlot().addDomainMarker(marker); } if (annotations != null) { for (XYAnnotation annotation : annotations) { if (annotation instanceof XYPointerAnnotation) { ((XYPointerAnnotation) annotation).setFont(ANNOTATION_FONT); } chart.getXYPlot().addAnnotation(annotation); } } // Add any bands to the chart if (adapter instanceof TimeSeriesChart) { final TimeSeriesChart tsc = (TimeSeriesChart) adapter; for (int i = 0; i < tsc.getBands().size(); i++) { final Color c = tsc.getBandColors().get(i); final Color fill = tsc.getBandFillColors().get(i); final XYDifferenceRenderer renderer = new XYDifferenceRenderer(fill, fill, false); renderer.setSeriesPaint(0, c); renderer.setSeriesPaint(1, c); renderer.setSeriesStroke(0, LineStyle.THICK.getStroke()); renderer.setSeriesStroke(1, LineStyle.THICK.getStroke()); chart.getXYPlot().setDataset(i + 1, tsc.getBands().get(i)); chart.getXYPlot().setRenderer(i + 1, renderer); } } } else if (adapter.getItems() instanceof CategoryDataset) { chart = ChartFactory.createBarChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(), (CategoryDataset) adapter.getItems(), PlotOrientation.VERTICAL, true, false, false); chart.getCategoryPlot().getDomainAxis().setLabelFont(LABEL_FONT); chart.getCategoryPlot().getRangeAxis().setLabelFont(LABEL_FONT); chart.getCategoryPlot().getDomainAxis().setTickLabelFont(LABEL_FONT); chart.getCategoryPlot().getRangeAxis().setTickLabelFont(LABEL_FONT); if (adapter.isAlwaysScaleFromZero()) { final double upperBound = chart.getCategoryPlot().getRangeAxis().getRange().getUpperBound(); final Range range = new Range(0, upperBound + (upperBound * 0.1)); chart.getCategoryPlot().getRangeAxis().setRange(range); } } else { throw new UnsupportedOperationException("Unsupported chart type: " + adapter.getItems().getClass()); } chart.getPlot().setNoDataMessage(NO_DATA_MESSAGE); return chart; }