List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:com.wicht.benchmark.utils.Benchs.java
/** * Generate the chart./*from w w w . j a va2 s. co m*/ * * @param title The title of the chart. * @param benchmarks The benchmarks to include in the chart. * @param sub A boolean tag indicating if we want to generate sub chart ({@code true}) or not ({@code * false}). * @param prefix The time prefix. */ private void generateChart(String title, Collection<NamedBenchmark> benchmarks, boolean sub, Prefix prefix) { String data = "Time (" + prefix.getSymbol() + "s)"; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (NamedBenchmark benchmark : benchmarks) { dataset.addValue(getExactMean(benchmark.getMean(), prefix), "", benchmark.getTitle()); } JFreeChart chart = ChartFactory.createBarChart(title.replace("-sub", ""), "Methods", data, dataset, PlotOrientation.VERTICAL, false, false, false); final CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setMaximumCategoryLabelLines(5); BufferedImage image = chart.createBufferedImage(width, height); try { ImageIO.write(image, "png", new File(folder + title + ".png")); } catch (IOException e) { e.printStackTrace(); } if (sub) { generateSubChart(title, benchmarks); } }
From source file:TelasBanzos.TelaRelatorioAproveitamento.java
/** * Creates new form TelaNovoOrcamento// w ww. j av a2 s. co m */ public TelaRelatorioAproveitamento() { initComponents(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(80, "0", "Nota"); dataset.setValue(70, "0", "Frequncia"); JFreeChart chart = ChartFactory.createBarChart("Aproveitamento", "Aproveitamento", "", dataset, PlotOrientation.VERTICAL, false, true, false); //colocar cor nas barras CategoryPlot plot = chart.getCategoryPlot(); BarRenderer render = (BarRenderer) plot.getRenderer(); render.setSeriesPaint(0, Color.blue); ChartPanel myChartPanel = new ChartPanel(chart, true); pnGraf.add(myChartPanel); setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("BanzosIcon.png")));//para setar um icone na janela }
From source file:com.att.aro.main.TraceOverviewPanel.java
/** * Initializes the Main panel and its various components. *//*from w w w . j av a 2 s . c o m*/ private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.traceoverview.title"), null, null, createDataset(null), PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis valueRangeAxis = plot.getDomainAxis(); valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f); valueRangeAxis.setMaximumCategoryLabelLines(2); valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT); valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(rb.getString("analysisresults.percentile")); rangeAxis.setRange(0.0, 100.0); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String traceInfo = ""; switch (arg2) { case TRACE_AVERAGE: traceInfo = rb.getString("tooltip.traceAnalysis.avg"); break; case TRACE_ENERGY: traceInfo = rb.getString("tooltip.traceAnalysis.engy"); break; case TRACE_OVERHEAD: traceInfo = rb.getString("tooltip.traceAnalysis.ovrhd"); break; } return traceInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100, 100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:com.att.aro.main.ProperSessionTerminationPanel.java
/** * Initializes the Panel for Proper Session Termination plot. */// ww w .ja v a 2 s. c o m private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.sessionoverview.title"), null, null, createDataset(null), PlotOrientation.HORIZONTAL, false, false, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); domainAxis.setMaximumCategoryLabelLines(2); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(rb.getString("analysisresults.percentage")); rangeAxis.setRange(0.0, 100.0); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String sessionInfo = ""; switch (arg2) { case SESSION_TERMINATION: sessionInfo = rb.getString("tooltip.sessionTermination"); break; case SESSION_TIGHT_CONN: sessionInfo = rb.getString("tooltip.sessionTightConn"); break; case SESSION_BURST: sessionInfo = rb.getString("tooltip.sessionBurst"); break; case SESSION_LONG_BURST: sessionInfo = rb.getString("tooltip.sessionLongBurst"); break; } return sessionInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100, 100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:Reportes.BarChart.java
public ChartPanel reporteEmpleados(DefaultCategoryDataset data) { JFreeChart JFchart = ChartFactory.createBarChart("Reporte de empleados", "Sedes", "Cantidad", data, PlotOrientation.VERTICAL, true, true, true); /*/* w ww . j av a 2s . c o m*/ CategoryPlot plot = new CategoryPlot(); ChartFrame chartFrame = new ChartFrame("Reporte de empleadoos", JFchart, false); chartFrame.setSize(300, 300); chartFrame.setVisible(true); */ CategoryPlot categoryP = JFchart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) categoryP.getRenderer(); renderer.setMaximumBarWidth(0.35); Color color = new Color(67, 165, 208); renderer.setSeriesPaint(0, color); ChartPanel panel = new ChartPanel(JFchart, true, true, true, false, false); panel.setSize(ancho, alto); return panel; }
From source file:Gui.admin.NouveauStatistique.java
private void StatistiquesBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StatistiquesBouttonActionPerformed int size = tablemesEvaluation.getRowCount(); List<Double> notes = new ArrayList<Double>(); List<Integer> ids = new ArrayList<Integer>(); List<String> noms = new ArrayList<String>(); EvaluationDAO evaluationDAO = new EvaluationDAO(); System.out.println("ouh ouh " + size); //System.out.println(evaluationDAO.getMoyenneByAdherent(8)); int idadh;// w ww . j a v a 2 s.c o m float ess; for (int i = 0; i < size; i++) { System.out.println(tablemesEvaluation.getValueAt(i, 4).toString()); idadh = Integer.parseInt(tablemesEvaluation.getValueAt(i, 1).toString()); String nom = (tablemesEvaluation.getValueAt(i, 2).toString()); // notes.add((new Double (tablemesEvaluation.getValueAt(i,2).toString()))); System.out.println(" id adherent " + idadh); // System.out.println("moyenne "+); ess = evaluationDAO.getMoyenneByAdherent(idadh); System.out.println(ess); // notes.add((new Double (evaluationDAO.getMoyenneByAdherent((int) tablemesEvaluation.getValueAt(i,1))))); notes.add((new Double(ess))); ids.add((int) tablemesEvaluation.getValueAt(i, 1)); noms.add(nom); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < size; i++) { dataset.setValue(new Double(notes.get(i)), "notes", new String(noms.get(i))); } //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Noms des adhrents", "Notes", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(700, 800); ValueMarker marker = new ValueMarker(15); marker.setLabel(" seuil de l'valuation "); marker.setLabelAnchor(RectangleAnchor.CENTER); marker.setPaint(Color.YELLOW); p.addRangeMarker(marker); p.setRangeGridlinePaint(Color.RED); try { } catch (Exception e) { } /* String note =noteTxt.getText(); String idAdherent=idAdherentEvaluText.getText(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(new Double(note), "notes", new Double(idAdherent)); //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p= chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(450,350); */ try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("statistiques.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } }
From source file:entropy.plan.visualization.GanttVisualizer.java
/** * Build the plan agenda//from w w w. j av a 2s. c o m * * @param plan the plan to visualize * @return {@code true} if the generation succeeds */ @Override public boolean buildVisualization(TimedReconfigurationPlan plan) { File parent = new File(out).getParentFile(); if (parent != null && !parent.exists() && !parent.mkdirs()) { Plan.logger.error("Unable to create '" + out + "'"); return false; } final TaskSeriesCollection collection = new TaskSeriesCollection(); TaskSeries ts = new TaskSeries("actions"); for (Action action : plan) { Task t = new Task(action.toString(), new SimpleTimePeriod(action.getStartMoment(), action.getFinishMoment())); ts.add(t); } collection.add(ts); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); final JFreeChart chart = ChartFactory.createGanttChart(null, // chart title "Actions", // domain axis label "Time", // range axis label collection, // data false, // include legend true, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); DateAxis da = (DateAxis) plot.getRangeAxis(); SimpleDateFormat sdfmt = new SimpleDateFormat(); sdfmt.applyPattern("S"); da.setDateFormatOverride(sdfmt); ((GanttRenderer) plot.getRenderer()).setShadowVisible(false); int width = 500 + 10 * plan.getDuration(); int height = 50 + 20 * plan.size(); try { switch (fmt) { case png: ChartUtilities.saveChartAsPNG(new File(out), chart, width, height); break; case jpg: ChartUtilities.saveChartAsJPEG(new File(out), chart, width, height); break; } } catch (IOException e) { Plan.logger.error(e.getMessage(), e); return false; } return true; }
From source file:userInterface.doctor.ReportingPatientVitalHistJPanel.java
private void weightJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weightJButtonActionPerformed // TODO add your handling code here: // TODO add your handling code here: DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel(); DefaultCategoryDataset weightbarChartSet = new DefaultCategoryDataset(); for (VitalSignInfo vhl : patient.getVitalHistory().getVitalHistory()) { weightbarChartSet.setValue(vhl.getWeight(), "Weight", vhl.getCurrentTime()); }/*from www. j a v a2 s.c o m*/ JFreeChart respChart = ChartFactory.createBarChart3D("Vital History", "Time", "Weight", weightbarChartSet, PlotOrientation.VERTICAL, false, true, false); respChart.setBackgroundPaint(Color.WHITE); respChart.getTitle().setPaint(Color.BLACK); CategoryPlot p = respChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Vital Information: Weight", respChart); frame.setVisible(true); frame.setSize(450, 350); }
From source file:edu.indiana.htrc.visual.HTRCBarChartDrawer.java
@Override public File draw() { System.out.println("draw bar!!!!!!!!!!!!!"); DefaultCategoryDataset bar_dataset = new DefaultCategoryDataset(); /*dataset.setValue(6, "Profit", "Jane"); dataset.setValue(7, "Profit", "Tom"); dataset.setValue(8, "Profit", "Jill"); dataset.setValue(5, "Profit", "John"); dataset.setValue(12, "Profit", "Fred");*/ Set<String> key_set = input_map.keySet(); Iterator<String> iter = key_set.iterator(); while (iter.hasNext()) { String key = iter.next(); int value = input_map.get(key); bar_dataset.setValue(value, dataset_label, key); }//from ww w .jav a 2 s . c o m JFreeChart chart = null; if (is3D) { chart = ChartFactory.createBarChart3D(chart_name, x_axis_label, y_axis_label, bar_dataset, PlotOrientation.VERTICAL, true, true, false); } else { chart = ChartFactory.createBarChart(chart_name, x_axis_label, y_axis_label, bar_dataset, PlotOrientation.VERTICAL, true, true, false); } CategoryPlot p = chart.getCategoryPlot(); /* NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());*/ BarRenderer renderer = (BarRenderer) p.getRenderer(); DecimalFormat decimalformat1 = new DecimalFormat("##"); StandardCategoryItemLabelGenerator label_generator = new StandardCategoryItemLabelGenerator("{2}", decimalformat1); renderer.setItemLabelGenerator(label_generator); final ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0/* -Math.PI / 2.0*/ ); renderer.setPositiveItemLabelPosition(pos); final CategoryAxis domainAxis = p.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); renderer.setMaximumBarWidth(.15); renderer.setItemLabelsVisible(true); chart.getCategoryPlot().setRenderer(renderer); File img = new File("../webapps/HTRC-UI-AuditAnalyzer/images/" + System.currentTimeMillis() + ".jpg"); try { ChartUtilities.saveChartAsJPEG(img, chart, 1400, 600); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } return img; }
From source file:userinterface.InventoryRole.InventoryWorkAreaJPanel.java
private void chartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chartButtonActionPerformed // TODO add your handling code here: int a = enterprise.getHash().get("A+"); int b = enterprise.getHash().get("A-"); int c = enterprise.getHash().get("B+"); int d = enterprise.getHash().get("B-"); int e = enterprise.getHash().get("AB+"); int f = enterprise.getHash().get("AB-"); int g = enterprise.getHash().get("O+"); int h = enterprise.getHash().get("O-"); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(a, "Quantity", "A+"); dataset.setValue(b, "Quantity", "A-"); dataset.setValue(c, "Quantity", "B+"); dataset.setValue(d, "Quantity", "B-"); dataset.setValue(e, "Quantity", "AB+"); dataset.setValue(f, "Quantity", "AB-"); dataset.setValue(g, "Quantity", "O+"); dataset.setValue(h, "Quantity", "O-"); JFreeChart chart = ChartFactory.createBarChart("BloodAvailability", "Blood Group", "Quantity", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame("Availability Bar Chart", chart); frame.setVisible(true);/*from w ww. j ava 2 s.co m*/ frame.setSize(450, 500); }