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:com.xilinx.kintex7.PowerChart.java
private void makeChart() { dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("", "Time Interval", "", dataset, PlotOrientation.HORIZONTAL, true, true, false);/*from w w w .j a v a 2 s . c om*/ TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15)); ttitle.setPaint(Color.WHITE); chart.setTitle(ttitle); chart.setBackgroundPaint(bg); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ValueAxis axis = plot.getRangeAxis(); axis.setUpperBound(6.0); axis.setLowerBound(0.0); axis.setTickLabelPaint(new Color(185, 185, 185)); CategoryAxis caxis = plot.getDomainAxis(); caxis.setTickLabelPaint(new Color(185, 185, 185)); caxis.setLabelPaint(new Color(185, 185, 185)); renderer.setItemMargin(0); renderer.setSeriesPaint(0, new Color(0x17, 0x7b, 0x7c)); renderer.setSeriesPaint(1, new Color(0xa2, 0x45, 0x73)); renderer.setSeriesPaint(2, new Color(0xff, 0x80, 0x40)); renderer.setSeriesPaint(3, new Color(0x6f, 0x2c, 0x85)); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000"))); addDummy(); }
From source file:eu.delving.stats.ChartHelper.java
private static JFreeChart createFieldFrequencyChart(Stats.RecordStats recordStats, Path path, String name) { Stats.Histogram histogram = recordStats.frequencies.get(path); if (histogram == null) return null; List<Stats.Counter> sorted = sort(histogram.counterMap.values(), MAX_BAR_CHART_SIZE, recordStats.recordCount);//ww w . j a v a2 s . co m DefaultCategoryDataset data = new DefaultCategoryDataset(); data.addValue(histogram.absent, "Frequency", "0"); for (Stats.Counter counter : sorted) data.addValue(counter.count, "Frequency", counter.value); JFreeChart chart = ChartFactory.createBarChart(String.format("Frequency within record in %s", name), "Occurrences", "Frequency", data, PlotOrientation.VERTICAL, false, true, false); chart.addSubtitle(new TextTitle(path.toString())); return finishBarChart(chart, new Color(30, 144, 225)); }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo1.java
/** * Creates a sample chart./*ww w . j ava2 s . c o m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { domainLabel = "Category"; rangeLabel = "Value"; // 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.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // 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); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. /*Summary s = new Summary(dataset); LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setBorder(new BlockBorder(1.0, 1.0, 1.0, 1.0)); LegendItemSource[] legendSource= legend.getSources(); LegendItemCollection old_legendItems = legendSource[0].getLegendItems(); LegendItemCollection new_legendItems = new LegendItemCollection(); int legendCount = old_legendItems.getItemCount(); for (int i=0; i<legendCount; i++){ LegendItem old_legendItem = old_legendItems.get(i); String legendLabel = old_legendItem.getLabel(); System.out.println("legendLabel="+old_legendLabel); LegendItem new_legendItem = new LegendItem( old_legendItem.getLabel()+s.getSummary(i), old_legendItem.getDescription(), old_legendItem.getToolTipText(), old_legendItem.getURLText(), old_legendItem.isShapeVisible(), old_legendItem.getShape(), old_legendItem.isShapeFilled(), old_legendItem.getFillPaint(), old_legendItem.isShapeOutlineVisible(), old_legendItem.getOutlinePaint(), old_legendItem.getOutlineStroke(), old_legendItem.isLineVisible(), old_legendItem.getLine(), old_legendItem.getLineStroke(), old_legendItem.getlinePaint() ); new_legendItems.add(new_legendItem); } // *** this is important - you need to add the item container to // the wrapper, otherwise the legend items won't be displayed when // the wrapper is drawn... *** BlockContainer items = legend.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend.setWrapper(wrapper); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legend);*/ setCategorySummary(dataset); return chart; }
From source file:Client.Gui.BarChart.java
/** * Creates a sample chart.//w w w .ja va 2 s .com * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Distribution of Trainging", // chart title "", // domain axis label "", // 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 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); final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.magenta, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp3); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:fitmon.WorkoutChart.java
/** * Creates a sample chart.//from w w w . ja v a 2s . c o m * * @param dataset the dataset. * * @return The chart. */ public JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("weekly workout", // chart title "Date", // domain axis label "Performance", // 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 = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(25, 200); 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.ORANGE, 0.0f, 0.0f, Color.lightGray); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.PINK, 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); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.xilinx.virtex7.PowerChart.java
private void makeChart() { dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("", "Time Interval", "", dataset, PlotOrientation.HORIZONTAL, true, true, false);//from w w w . j av a 2 s .co m TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15)); ttitle.setPaint(Color.WHITE); chart.setTitle(ttitle); chart.setBackgroundPaint(bg); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ValueAxis axis = plot.getRangeAxis(); axis.setUpperBound(10.0); TickUnits tickUnits = new TickUnits(); tickUnits.add(new NumberTickUnit(2)); axis.setStandardTickUnits(tickUnits); axis.setLowerBound(0.0); axis.setTickLabelPaint(new Color(185, 185, 185)); CategoryAxis caxis = plot.getDomainAxis(); caxis.setTickLabelPaint(new Color(185, 185, 185)); caxis.setLabelPaint(new Color(185, 185, 185)); renderer.setItemMargin(0); renderer.setSeriesPaint(0, new Color(0x17, 0x7b, 0x7c)); renderer.setSeriesPaint(1, new Color(0xa2, 0x45, 0x73)); renderer.setSeriesPaint(2, new Color(0xff, 0x80, 0x40)); renderer.setSeriesPaint(3, new Color(0x6f, 0x2c, 0x85)); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000"))); addDummy(); }
From source file:Reportes.BarChart.java
public ChartPanel reporteOrdenesEmpresa(DefaultCategoryDataset data) { JFreeChart chart = ChartFactory.createBarChart("Reporte de ordenes de trabajo por sede", "Sedes", "Cantidad", data, PlotOrientation.VERTICAL, true, true, true); CategoryPlot categoryP = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) categoryP.getRenderer(); renderer.setMaximumBarWidth(0.35);// w w w. j a v a2s .c o m 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:result.analysis.Chart.java
void batchAcrossSemesters(String batch, String[] colleges) { db = mongoClient.getDB("rnsit"); analyz = new Analyze(db); final String fcd = "F.C.D"; final String fc = "F.C"; final String fail = "FAIL"; final String sc = "S.C"; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String collection_name;// w w w. j a v a 2 s . c om int start_index = 1, end_index = 8; for (int i = start_index; i <= end_index; i++) { collection_name = "cs_" + batch + "_" + i + "_sem"; DBCollection collection = db.getCollection(collection_name); double number = analyz.GetNumber(collection, "FAIL"); dataset.addValue(number, fail, "Sem " + i); number = analyz.GetNumber(collection, "FIRST CLASS"); dataset.addValue(number, fc, "Sem " + i); number = analyz.GetNumber(collection, "SECOND CLASS"); dataset.addValue(number, sc, "Sem " + i); number = analyz.GetNumber(collection, "FIRST CLASS WITH DISTINCTION"); dataset.addValue(number, fcd, "Sem " + i); } JFreeChart barChart = ChartFactory.createBarChart("Sem Wise Performance", "SEMESTER", "NUMBER", dataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame = new ChartFrame("Semester Wise Performance of " + batch + " year", barChart); frame.setVisible(true); frame.setSize(500, 500); save_jpeg(barChart); }
From source file:Balo.Main.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO dadd your handling code here: DefaultCategoryDataset barChart = new DefaultCategoryDataset(); barChart.setValue(200, "Contribution Amount", "January"); barChart.setValue(550, "Contribution Amount", "February"); barChart.setValue(300, "Contribution Amount", "March"); JFreeChart jbarChart = ChartFactory.createBarChart("Bar chart", "Monthly", "Contribution Amount", barChart, PlotOrientation.HORIZONTAL, true, true, true); CategoryPlot barchrt = (CategoryPlot) jbarChart.getPlot(); barchrt.setRangeGridlinePaint(Color.BLUE); ChartPanel barPanel = new ChartPanel(jbarChart); barPanel.setPreferredSize(new Dimension(785, 440)); //size according to my window barPanel.setMouseWheelEnabled(true); JPanel jPanel = new JPanel(); jPanel.add(barPanel);/*ww w. ja va2s.c om*/ String filename = "F:barchart.jpg"; try { ChartUtilities.saveChartAsJPEG(new File(filename), jbarChart, 500, 300); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.esprit.charts.JfreeChart.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int i = 0;// w w w.j ava 2s .c o m int j = 0; List<Reservation> listReservation = ReservationDAO.getInstance().DisplayAllReservation(); for (Reservation listReservation1 : listReservation) { i++; } List<Client> listClient = ClientDAO.getInstance().DisplayAllClients(); for (Client listClient1 : listClient) { j++; } try { dataset.setValue(i, "", "t1"); dataset.setValue(j, "", "t2"); JFreeChart chart = ChartFactory.createBarChart("Statistiques", "", "", dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot catPlot = chart.getCategoryPlot(); ChartPanel ChartPanel = new ChartPanel(chart); jPanel1.removeAll(); jPanel1.add(ChartPanel, BorderLayout.CENTER); jPanel1.validate(); } catch (Exception e) { System.out.println(i); } }