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:kcse_2013_results.BarChartExample.java
public static void main(String[] args) { // Create a simple Bar chart DefaultCategoryDataset 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"); JFreeChart chart = ChartFactory.createBarChart("Comparison between Salesman", "Salesman", "Profit", dataset, PlotOrientation.VERTICAL, false, true, false); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final int width = screenSize.width; final int height = screenSize.height; try {//from w w w. j a va2s . c o m ChartUtilities.saveChartAsJPEG(new File("C:\\Users\\Wachira\\Desktop\\chart.jpg"), chart, width, height); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:org.jfree.chart.demo.ImageMapDemo1.java
/** * Starting point for the demo.//from w ww. j a v a 2 s. c o m * * @param args ignored. */ public static void main(final String[] args) { // create a chart final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 }, { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 }, { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); JFreeChart chart = null; final boolean drilldown = true; if (drilldown) { final CategoryAxis categoryAxis = new CategoryAxis("Category"); final ValueAxis valueAxis = new NumberAxis("Value"); final BarRenderer renderer = new BarRenderer(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createBarChart("Vertical Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("barchart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("barchart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"barchart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:DataCharts.BarGraph.java
public static JFreeChart createChart(CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart("Customers in 2015", "Month", "Amount", dataset, PlotOrientation.VERTICAL, true, true, false); return chart; }
From source file:br.unicamp.cst.util.ChartViewerUtil.java
public static synchronized ChartPanel createChart(DefaultCategoryDataset dataset, String title, String categoryAxisLabel, String valueAxisLabel, PlotOrientation chartType) { final JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, dataset, chartType, true, true, false); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); chart.setBackgroundPaint(Color.lightGray); ChartPanel localChartPanel = new ChartPanel(chart); localChartPanel.setVisible(true);// w ww .j av a 2s . c o m localChartPanel.setDomainZoomable(true); return localChartPanel; }
From source file:org.jfree.chart.demo.GradientPaintTransformerDemo1.java
private static JFreeChart createChart(String s, CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart(s, null, "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setItemMargin(0.02D);//from w w w .java 2 s .c o m return jfreechart; }
From source file:by.bsuir.group172301.matskevich.tour.util.PDFCreator.java
public static JFreeChart generateBarChart(int init, int posle) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); dataSet.setValue(init, "?", "Before"); dataSet.setValue(posle, "?", "After"); JFreeChart chart = ChartFactory.createBarChart("Tendention", "Tests", "Quantity", dataSet, PlotOrientation.VERTICAL, false, true, false); return chart; }
From source file:statistic.ca.gui.Charts.java
public static JFreeChart createBarChart(ChartData data) { if (data.getDiagramType().equals("bar")) { chart = ChartFactory.createBarChart(data.getTitle(), // Title data.getYAxisLabel(), // X-Axis label "", // Y-Axis label data.getCDataSet(), // CategoryDataset PlotOrientation.VERTICAL, false, true, false // Show legend );//from w ww .j a va 2 s . c om CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); } if (data.getDiagramType().equals("pie")) { chart = ChartFactory.createPieChart(data.getTitle(), // Title data.getPieDataSet(), false, true, false); } chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:org.jfree.chart.demo.EventFrequencyDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("Event Frequency Demo", "Category", "Value", categorydataset, PlotOrientation.HORIZONTAL, true, true, false); jfreechart.setBackgroundPaint(new Color(255, 255, 204)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F); categoryplot.setRangeAxis(new DateAxis("Date")); StandardCategoryToolTipGenerator standardcategorytooltipgenerator = new StandardCategoryToolTipGenerator("", DateFormat.getDateInstance()); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(false, true); lineandshaperenderer.setBaseToolTipGenerator(standardcategorytooltipgenerator); categoryplot.setRenderer(lineandshaperenderer); return jfreechart; }
From source file:org.jfree.chart.demo.ParetoChartDemo1.java
public static JFreeChart createChart(CategoryDataset acategorydataset[]) { JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects", acategorydataset[0], PlotOrientation.VERTICAL, true, true, false); jfreechart.addSubtitle(new TextTitle("By Programming Language")); jfreechart.addSubtitle(new TextTitle("As at 5 March 2003")); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setLowerMargin(0.02D);/* w w w . j a v a2s . co m*/ categoryaxis.setUpperMargin(0.02D); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); NumberAxis numberaxis1 = new NumberAxis("Percent"); numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance()); categoryplot.setRangeAxis(1, numberaxis1); categoryplot.setDataset(1, acategorydataset[1]); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.mapDatasetToRangeAxis(1, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return jfreechart; }
From source file:org.jfree.chart.demo.CategoryLabelPositionsDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("CategoryLabelPositionsDemo1", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setMaximumCategoryLabelLines(0x7fffffff); categoryaxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.78539816339744828D)); return jfreechart; }