List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:org.jfree.chart.demo.WaterfallChartDemo.java
/** * Returns the chart.// w w w. j ava 2 s. co m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category", "Cost Per Unit", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final ValueAxis rangeAxis = plot.getRangeAxis(); // create a custom tick unit collection... final DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(5, formatter)); standardUnits.add(new NumberTickUnit(10, formatter)); standardUnits.add(new NumberTickUnit(20, formatter)); standardUnits.add(new NumberTickUnit(50, formatter)); standardUnits.add(new NumberTickUnit(100, formatter)); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); rangeAxis.setStandardTickUnits(standardUnits); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); final DecimalFormat labelFormatter = new DecimalFormat("$##,###.00"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); // renderer.setLabelGenerator( // new StandardCategoryLabelGenerator("{2}", labelFormatter) // ); renderer.setItemLabelsVisible(true); return chart; }
From source file:net.sourceforge.subsonic.controller.FolderChartController.java
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) { JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);//from w ww .j a v a 2s .c o m CategoryPlot plot = chart.getCategoryPlot(); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); LogarithmicAxis rangeAxis = new LogarithmicAxis(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setAllowNegativesFlag(true); // rangeAxis.setTickUnit(new NumberTickUnit(.1, new DecimalFormat("##0%"))); plot.setRangeAxis(rangeAxis); // Disable bar outlines. BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // Set up gradient paint for series. GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64)); renderer.setSeriesPaint(0, gp0); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 11)); renderer.setItemLabelAnchorOffset(-45.0); renderer.setSeriesItemLabelPaint(0, Color.white); renderer.setBaseItemLabelPaint(Color.white); // Rotate labels. CategoryAxis domainAxis = plot.getDomainAxis(); // domainAxis.setCategoryLabelPositions(); // domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); return chart; }
From source file:net.sqs2.omr.result.export.chart.ChartImageWriter.java
public void saveBarChart(OutputStream outputStream, String categoryAxisLabel, String valueAxisLabel, DefaultCategoryDataset dataSet) { String title = ""; boolean legend = false; boolean tooltips = true; boolean urls = false; JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, dataSet, PlotOrientation.HORIZONTAL, legend, tooltips, urls); CategoryPlot plot = chart.getCategoryPlot(); setSectionPaint(dataSet, plot);//from ww w . j ava 2 s . c o m try { ChartUtilities.writeChartAsPNG(outputStream, chart, this.width, this.height); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JFreeChart createBarChart(String xAxisLabel, String yAxisLabel, CategoryDataset dataset) { if (dataset == null) { throw new IllegalArgumentException("No dataset."); }/*from w ww. j a va2s .c o m*/ JFreeChart jfreechart = ChartFactory.createBarChart(null, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY); categoryplot.getRangeAxis().setLabelFont(UIConstants.H5_FONT); categoryplot.getDomainAxis().setLabelFont(UIConstants.H5_FONT); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setShadowVisible(false); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryMargin(0.02D); categoryaxis.setUpperMargin(0.01D); categoryaxis.setLowerMargin(0.01D); // categoryaxis.setAxisLineVisible(false); categoryaxis.setMaximumCategoryLabelWidthRatio(0.95F); NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis(); axis.setRangeType(RangeType.POSITIVE); return jfreechart; }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JFreeChart createTopNBarChart(String yAxisLabel, CategoryDataset dataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset, PlotOrientation.HORIZONTAL, true, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null);//from ww w . j ava 2 s.c om categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); barrenderer.setShadowVisible(false); barrenderer.setItemMargin(0.015); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); barrenderer.setSeriesPaint(1, UIConstants.INTEL_LIGHT_BLUE); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryMargin(0.15D); categoryaxis.setUpperMargin(0.02D); categoryaxis.setLowerMargin(0.02D); categoryaxis.setMaximumCategoryLabelWidthRatio(0.5F); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setRangeType(RangeType.POSITIVE); numberaxis.setStandardTickUnits(createLargeNumberTickUnits()); numberaxis.setUpperMargin(0.20000000000000001D); numberaxis.setLabelFont(UIConstants.H5_FONT); numberaxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0)); numberaxis.setTickMarksVisible(true); numberaxis.setTickLabelsVisible(true); LegendTitle legend = jfreechart.getLegend(); legend.setFrame(BlockBorder.NONE); legend.setItemFont(barrenderer.getBaseItemLabelFont().deriveFont(10.0f)); return jfreechart; }
From source file:userinterface.AdministratorWorkArea.PopularDoctorJPanel.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); int i = 1;/*w ww .j a v a2 s . co m*/ for (Employee doctor : docOrg.getEmployeeDirectory().getEmployeeList()) { dataSet.setValue(doctor.getPatientCount(), "Number of Patients Assigned to the Doctor", doctor.getName()); i++; } JFreeChart chart = ChartFactory.createBarChart("Doctor Patient Graph", "Doctor Name", "Number Of Patients", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Number of Patients Assigned to the Doctor", chart); frame.setVisible(true); frame.setSize(800, 550); }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
@SuppressWarnings("unchecked") public static JFreeChart createTopNBarChart2(String yAxisLabel, CategoryDataset dataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null);//from w w w.j a v a2 s . c om categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(UIConstants.INTEL_BORDER_GRAY); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.75D); NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis(); axis.setRangeType(RangeType.POSITIVE); axis.setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setShadowVisible(false); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(UIConstants.H5_FONT); barrenderer.setBarPainter(new StandardBarPainter()); List<String> names = dataset.getColumnKeys(); for (String name : names) { CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation(name, name, 0.0D); categorytextannotation.setFont(UIConstants.H6_FONT); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.MIDDLE); categoryplot.addAnnotation(categorytextannotation); } return jfreechart; }
From source file:josejamilena.pfc.analizador.GraficoPorSGBD.java
public GraficoPorSGBD(final String sgbd, final String script) throws ClassNotFoundException, SQLException { Map<String, String> res = new TreeMap<String, String>(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Statement stmt = null;/*ww w. j a v a 2 s .c o m*/ ResultSet rs = null; String consulta = "select tiempo, fecha from estadisticas where tipo=\'" + script + "\' and host_sgbd=\'" + sgbd + "\'"; stmt = App.conn.createStatement(); rs = stmt.executeQuery(consulta); while (rs.next()) { res.put(rs.getString(2), rs.getString(1)); } rs.close(); stmt.close(); Iterator it = res.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); dataset.setValue(Double.parseDouble(pairs.getValue().toString()), script, pairs.getKey().toString()); } JFreeChart chart = ChartFactory.createBarChart(sgbd, // chart title "Hora", // domain axis label "Duracin (milisegundos)", // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false); CategoryPlot plot = chart.getCategoryPlot(); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); ChartPanel chartPanel = new ChartPanel(chart); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add((new JPanel()).add(chartPanel)); setContentPane(scrollPane); }
From source file:UserInterface.DoctorRole.DoctorReportChartJPanel.java
private void personneljButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_personneljButton3ActionPerformed // TODO add your handling code here: ReportToReporter report = enterprise.getReport(); if (report.getStatus() != null) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(report.getTimeofadmin(), "Adminstration", "Adminstration"); dataset.addValue(report.getTimeofnurse(), "Nurse", "Nurse"); dataset.addValue(report.getTimeofpathology(), "Pathologist", "Pathologist"); dataset.addValue(report.getTimeofphar(), "Pharmacist", "Pharmacist"); dataset.addValue(report.getTimeofphysician(), "Physician", "Physician"); dataset.addValue(report.getTimeofsurgeon(), "Surgeon", "Surgeon"); //dataset.setValue(80, "masd", "sss"); JFreeChart chart = ChartFactory.createBarChart("Personnel", "Position", "Times", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.WHITE); ChartFrame frame = new ChartFrame("Chart for ERROR", chart); frame.setVisible(true);//from www . ja v a 2 s .c o m frame.setSize(550, 550); } else { JOptionPane.showMessageDialog(null, "Sorry, the final report has not been generated"); } }
From source file:josejamilena.pfc.analizador.GraficoPorCliente.java
public GraficoPorCliente(final String cliente, final String script) throws ClassNotFoundException, SQLException { Map<String, String> res = new TreeMap<String, String>(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Statement stmt = null;//from www .j a va 2 s . c o m ResultSet rs = null; String consulta = "select tiempo, fecha from estadisticas where tipo=\'" + script + "\' and host_cliente=\'" + cliente + "\'"; stmt = App.conn.createStatement(); rs = stmt.executeQuery(consulta); while (rs.next()) { res.put(rs.getString(2), rs.getString(1)); } rs.close(); stmt.close(); Iterator it = res.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); dataset.setValue(Double.parseDouble(pairs.getValue().toString()), script, pairs.getKey().toString()); } JFreeChart chart = ChartFactory.createBarChart(cliente, // chart title "Hora", // domain axis label "Duracin (milisegundos)", // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false); CategoryPlot plot = chart.getCategoryPlot(); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); ChartPanel chartPanel = new ChartPanel(chart); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add((new JPanel()).add(chartPanel)); setContentPane(scrollPane); }