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:lab10part2.Chart.java
private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w ww . ja v a2s .c o m*/ // 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... 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 CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:Reportes.BarChart.java
public ChartPanel reporteCantidadCotizacionesEmpresa(DefaultCategoryDataset data) { JFreeChart chart = ChartFactory.createBarChart("Reporte de cantidad de cotizaciones por sede", "Sede", "Cantidad", data, PlotOrientation.VERTICAL, true, true, true); CategoryPlot categoryP = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) categoryP.getRenderer(); renderer.setMaximumBarWidth(0.35);//from w w w . j ava 2 s.com Color color = new Color(67, 165, 208); renderer.setSeriesPaint(0, color); ChartPanel panel = new ChartPanel(chart, true, true, true, false, false); panel.setSize(ancho, alto); return panel; }
From source file:org.owasp.jbrofuzz.graph.canvas.ResponseHeaderSizeChart.java
public ChartPanel getPlotCanvas() { final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Response Header Size Bar Chart", // chart title "File Name", // domain axis label "Response Header Size (bytes)", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? true // URLs? );/* www . j a v a2 s.c o m*/ final Plot plot = chart.getPlot(); plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage()); plot.setBackgroundImageAlignment(Align.TOP_RIGHT); final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); return new ChartPanel(chart); }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo4.java
/** * Creates a sample chart.// w w w . j av a2 s. c o m * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // 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(0xBBBBDD)); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); // 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); renderer.setMaximumBarWidth(0.10); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); // OPTIONAL CUSTOMISATION COMPLETED. renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:com.metricsplugin.charts.BarChart.java
/** * Creates a sample chart.//from ww w. j a v a2 s. c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(name, // chart title labels[0], // domain axis label labels[1], // 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:org.pentaho.plugin.jfreereport.reportcharts.BarChartExpression.java
public JFreeChart computeCategoryChart(final CategoryDataset categoryDataset) { final PlotOrientation orientation = computePlotOrientation(); final JFreeChart chart; if (isThreeD()) { if (isStacked()) { chart = ChartFactory.createStackedBarChart3D(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, orientation, isShowLegend(), false, false); } else {/*from w w w . ja v a2 s . co m*/ chart = ChartFactory.createBarChart3D(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, orientation, isShowLegend(), false, false); } chart.getCategoryPlot().setDomainAxis(new FormattedCategoryAxis3D(getCategoryAxisLabel(), getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale())); } else { if (isStacked()) { chart = ChartFactory.createStackedBarChart(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, orientation, isShowLegend(), false, false); } else { chart = ChartFactory.createBarChart(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, orientation, isShowLegend(), false, false); } chart.getCategoryPlot().setDomainAxis(new FormattedCategoryAxis(getCategoryAxisLabel(), getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale())); } final CategoryPlot plot = (CategoryPlot) chart.getPlot(); configureLogarithmicAxis(plot); return chart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo3.java
/** * Creates a chart.//w w w.j a va 2 s . c om * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.getPlot().setOutlinePaint(null); final TextTitle title = new TextTitle("Figure 6 | Overall SEO Rating"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = chart.getCategoryPlot(); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(0.0, 4.0); rangeAxis.setVisible(false); final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null); domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); domainAxis.setCategoryMargin(0.30); domainAxis.addSubLabel("Sm.", "(10)"); domainAxis.addSubLabel("Med.", "(10)"); domainAxis.addSubLabel("Lg.", "(10)"); domainAxis.addSubLabel("All", "(10)"); final CategoryLabelPositions p = domainAxis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); plot.setDomainAxis(domainAxis); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setBaseOutlineStroke(null); // final StandardCategoryLabelGenerator generator = new StandardCategoryLabelGenerator( // "{2}", new DecimalFormat("0.00") // ); // renderer.setLabelGenerator(generator); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition()); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo2.java
/** * Creates a chart.//from w ww . j ava 2s .c om * * @param dataset the dataset. * * @return A chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation !legendPanelOn, // include legend true, false); // 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(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}")); // OPTIONAL CUSTOMISATION COMPLETED. renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:Software_Jframes.chart.java
public void barchart(JDesktopPane jdesktop) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); try {//www . j ava2 s.c om ResultSet rs = db.statement().executeQuery("select date,name,amount from other_exp"); while (rs.next()) { String date = rs.getString("date"); String name = rs.getString("name"); String amnt = rs.getString("Amount"); int amount = Integer.parseInt(amnt); dataset.setValue(amount, name, date); } } catch (Exception e) { } JFreeChart chart = ChartFactory.createBarChart("Other Expenses for Last week", "Date", "Expense", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setBackgroundPaint(Color.WHITE); p.setRangeGridlinePaint(Color.black); ChartPanel panel = new ChartPanel(chart); jdesktop.add(panel).setSize(550, 230); }
From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java
/** * Creates a sample chart.//from w w w . ja va2s. c o m * * @param dataset the dataset. * * @return The chart. */ public static JFreeChart createChart(final CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("", // chart title "X-value", // domain axis label "Y-value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, false); chart.addSubtitle(new TextTitle("http://www.bupt.edu.cn", new Font("", Font.ITALIC, 10))); // chart.setBackgroundPaint(Color.white); // chart.setBackgroundPaint(Color.getHSBColor(2, 29, 100)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); // renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1);// categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // 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); chart.getTitle().setFont(new Font("", Font.PLAIN, 16));// CategoryAxis domainAxis = plot.getDomainAxis(); // domainAxis.setLabelFont(new Font("", Font.PLAIN, 14)); // domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10)); // rangeAxis.setLabelFont(new Font("", Font.PLAIN, 15)); chart.getLegend().setItemFont(new Font("", Font.PLAIN, 15)); return chart; }