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:org.jfree.chart.demo.XYDrawableAnnotationDemo1.java
private static JFreeChart createBarChart() { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); defaultcategorydataset.addValue(10D, "R1", "Q1"); defaultcategorydataset.addValue(7D, "R1", "Q2"); defaultcategorydataset.addValue(8D, "R1", "Q3"); defaultcategorydataset.addValue(4D, "R1", "Q4"); defaultcategorydataset.addValue(10.6D, "R2", "Q1"); defaultcategorydataset.addValue(6.0999999999999996D, "R2", "Q2"); defaultcategorydataset.addValue(8.5D, "R2", "Q3"); defaultcategorydataset.addValue(4.2999999999999998D, "R2", "Q4"); JFreeChart jfreechart = ChartFactory.createBarChart("Sales 2008", null, null, defaultcategorydataset, PlotOrientation.VERTICAL, false, false, false); jfreechart.setBackgroundPaint(null); jfreechart.getPlot().setBackgroundPaint(new Color(200, 200, 255, 60)); return jfreechart; }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java
public JFreeChart getChart(CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("? ?", // chart title "", // domain axis label "? (.)", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w w w . j a va 2 s.com*/ // 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); // final IntervalMarker target = new IntervalMarker(2000000, 3000000); // target.setLabel(" "); // target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); // target.setLabelAnchor(RectangleAnchor.LEFT); // target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); // target.setPaint(new Color(222, 222, 255, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); // 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.setItemMargin(0.10); // 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 / 4.0) // CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) ); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.others.CumulativeCurveChart.java
public JFreeChart createChart(DatasetMap datasetMap) { CategoryDataset datasetValue = (CategoryDataset) datasetMap.getDatasets().get("1"); CategoryDataset datasetCumulative = (CategoryDataset) datasetMap.getDatasets().get("2"); JFreeChart chart = ChartFactory.createBarChart(name, // chart title xLabel, // domain axis label yLabel, // range axis label datasetValue, // data PlotOrientation.VERTICAL, true, // include legend true, false);//from ww w. ja v a 2 s .c o m 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); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(1, axis2); plot.setDataset(1, datasetCumulative); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:org.getobjects.samples.HelloChart.Main.java
/** * This defines the direct action which can be invoked using:<pre> * /HelloThumbnail/wa/Main/chart?chs=128x128&chartType=p3</pre> * /*from w ww. j ava 2 s.c o m*/ * <p> * Note that the method returns a java.awt.BufferedImage. This will get * rendered to a GIF image by the GoDefaultRenderer. * (this method does not return a WOResponse, but it lets the Go machinery * deal with the image result object). * * @return a BufferedImage containing the scaled image */ public Object chartAction() { Dimension size = UGoogleChart.getDimensions(F("chs", "128x128"), null); String chartType = (String) F("cht", "p"); JFreeChart chart = null; if (chartType.equals("p")) { chart = ChartFactory.createPieChart((String) F("title", "Revenue Chart" /* default title */), this.getPieDataset(), UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } else if (chartType.equals("p3")) { chart = ChartFactory.createPieChart3D((String) F("title", "Revenue Chart" /* default title */), this.getPieDataset(), UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } else if (chartType.startsWith("b")) { // bhs, bvs (one bar with multiple values) // bhg, bvg (one bar for each row) PlotOrientation orientation = PlotOrientation.VERTICAL; if (chartType.startsWith("bh")) orientation = PlotOrientation.HORIZONTAL; if (chartType.endsWith("3")) { chart = ChartFactory.createBarChart3D((String) F("title", "Revenue Chart" /* default title */), (String) F("xlabel", "X-Axis"), (String) F("ylabel", "Y-Axis"), getCatDataSet(), orientation, UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } else { chart = ChartFactory.createBarChart((String) F("title", "Revenue Chart" /* default title */), (String) F("xlabel", "X-Axis"), (String) F("ylabel", "Y-Axis"), getRevCatDataSet(), orientation, UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } } /* style the chart */ chart.setBorderVisible(true); //chart.setBorderPaint(new Paint(Color.blue)); Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue); chart.setBackgroundPaint(p); /* style the plot */ Plot plot = chart.getPlot(); plot.setBackgroundPaint(new Color(240, 240, 250)); /* add explosion for Pies */ if (plot instanceof PiePlot) { PiePlot pplot = (PiePlot) chart.getPlot(); pplot.setExplodePercent("Products", 0.30); // can be multiple explodes } /* create the image for HTTP delivery */ return chart.createBufferedImage(size.width, size.height); }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo7.java
/** * Creates a sample chart.// www . ja va2 s . com * * @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, // orientation !legendPanelOn, // 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 = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); IntervalMarker target = new IntervalMarker(4.5, 7.5); target.setLabel("Target Range"); target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); target.setLabelAnchor(RectangleAnchor.LEFT); target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); target.setPaint(new Color(222, 222, 255, 128)); plot.addRangeMarker(target, Layer.BACKGROUND); // 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.setItemMargin(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); 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); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); renderer.setBaseItemLabelGenerator(new CustomCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(p); ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0); renderer.setPositiveItemLabelPositionFallback(p2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createBarChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from w w w . j av a 2s . c o m chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // 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)); return chart; }
From source file:org.amanzi.splash.chart.Charts.java
/** * Creates a bar chart/*from w ww . ja v a2s.c o m*/ * * @param reportChart chart model * @return a JFreeChart */ public static JFreeChart createBarChart(Chart reportChart) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(reportChart.getTitle(), // chart title reportChart.getDomainAxisLabel(), // domain axis label reportChart.getRangeAxisLabel(), // range axis label ((CategoryPlot) reportChart.getPlot()).getDataset(), // data reportChart.getOrientation(), // 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... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // 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)); renderer.setSeriesPaint(0, gp0); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:pidev.gui.FrameStat.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(80, "Marks", "Student1"); dataset.setValue(50, "Marks", "Student2"); dataset.setValue(75, "Marks", "Student3"); dataset.setValue(95, "Marks", "Student4"); JFreeChart chart = ChartFactory.createBarChart("Student score", "Student Name", "Marks", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame("Bar Chart for student", chart); frame.setVisible(true);/*from w w w. ja v a2s .c o m*/ frame.setSize(450, 350); }
From source file:org.vimarsha.ui.DataLoaderForm.java
private void drawBarChart(DefaultCategoryDataset data) { JFreeChart chart = ChartFactory.createBarChart("Binned event data", "bins", "count", data, PlotOrientation.HORIZONTAL, false, false, false); this.attributeDetailsChart.setChart(chart); this.attributeDetailsChart.setVisible(true); }
From source file:BarChartDemo.java
/** * Creates a sample chart./*from w w w .j a va 2s .com*/ * * @param dataset the dataset. * * @return The chart. */ 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? ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... 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)); return chart; }