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:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java
private static JFreeChart createChart(BarGraphDataSeries dataSeries) { if (dataSeries == null) return null; BarGraphDataSeries ds = dataSeries;/*from w ww.j av a2 s .c o m*/ // create the chart... JFreeChart chart = ChartFactory.createBarChart(ds.getTitle(), // chart title ds.getDomainLabel(), // domain axis label ds.getRangeLabel(), // range axis label ds.getDataSet(0), // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); // 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)); GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp3); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); ValueRange vr = ds.getRangeValueRanges().get(0); if (vr != null) { Range range = new Range(vr.getMin() / vr.getScale(), vr.getMax() / vr.getScale()); rangeAxis.setRange(range); } return chart; }
From source file:br.ufba.eleicoestransparentes.view.chart.GraficoBarra.java
/** * Creates a sample chart.//from www .j av a2s. co m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset, String titulo) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart(titulo, // chart title "Doador", // domain axis label "Valor", // 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... 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); renderer.setSeriesPaint(0, gp0); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.xilinx.ultrascale.gui.BarCharts.java
License:asdf
private void makeChart(String name) { dataset = new DefaultCategoryDataset(); // chart = ChartFactory.createLineChart("", "", name, dataset, PlotOrientation.VERTICAL, true, true, false); // chart = ChartFactory.createBarChart("asd", "asd", "asdffa", dataset, PlotOrientation.HORIZONTAL, true, true, false); chart = ChartFactory.createBarChart("power", "Time Interval", "Throughput (Gbps)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(bg);//from ww w.jav a2 s. c o m TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15)); ttitle.setPaint(Color.BLACK); chart.setTitle(ttitle); CategoryPlot plot = chart.getCategoryPlot(); // BarRenderer renderer = (BarRenderer)plot.getRenderer(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ValueAxis axis = plot.getRangeAxis(); upperBounds(65); axis.setTickLabelPaint(new Color(0, 0, 0));//(185, 185, 185) axis.setLabelPaint(new Color(0, 0, 0)); CategoryAxis caxis = plot.getDomainAxis(); caxis.setTickLabelPaint(new Color(0, 0, 0)); caxis.setLabelPaint(new Color(0, 0, 0)); renderer.setItemMargin(0); renderer.setSeriesPaint(0, new Color(0x2e, 0x90, 0x18));//(0x17, 0x7b, 0x7c)); renderer.setSeriesPaint(1, new Color(0x12, 0x45, 0x73));//(0xa2, 0x45, 0x73) renderer.setSeriesPaint(3, new Color(0xff, 0x80, 0x40)); renderer.setSeriesPaint(2, new Color(0x6f, 0x2c, 0x85)); // renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000"))); //renderer.setMaximumBarWidth(0.05); addDummy(); }
From source file:com.mycompany.task1.Chart.java
private JFreeChart displayChart(DefaultCategoryDataset dataSet) { JFreeChart chart;//w ww .j a v a2s . c o m chart = ChartFactory.createBarChart("Irysy", "ilo", " ", dataSet, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = chart.getCategoryPlot(); //chart.removeLegend(); plot.setRangeGridlinePaint(Color.black); ChartFrame frame; frame = new ChartFrame("Irysy", chart); frame.setVisible(true); frame.setSize(700, 550); return chart; }
From source file:fr.crnan.videso3d.ihm.PLNSPanel.java
private void createIHM() { CategoryDataset dataset;/*w w w. j a v a 2 s.c o m*/ try { dataset = plnsAnalyzer.getCategoryCodesRepartition(); addChart(ChartFactory.createBarChart("Rpartition de l'utilisation des codes par catgorie", "Catgorie", "Total", dataset, PlotOrientation.VERTICAL, false, true, false)); } catch (DatabaseNotFoundException e) { e.printStackTrace(); } dataset = plnsAnalyzer.getLPCodesRepartition(); // CategoryAxisLabel is used in PLNSChartMouseListener to determine the // type of the entity addChart(ChartFactory.createBarChart("Rpartition de l'utilisation des codes par LP", "LP", "Total", dataset, PlotOrientation.VERTICAL, false, true, false)); }
From source file:com.att.aro.ui.view.overviewtab.ConnectionStatisticsChartPanel.java
public JFreeChart initializeChart() { JFreeChart chart = ChartFactory.createBarChart( ResourceBundleHelper.getMessageString("overview.sessionoverview.title"), null, null, createDataset(), PlotOrientation.HORIZONTAL, false, false, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); domainAxis.setMaximumCategoryLabelLines(2); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentage")); rangeAxis.setRange(0.0, 100.0);//w w w . j av a2 s . c o m rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String sessionInfo = ""; switch (arg2) { case SESSION_TERMINATION: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTermination"); break; case SESSION_TIGHT_CONN: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTightConn"); break; case SESSION_BURST: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionBurst"); break; case SESSION_LONG_BURST: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionLongBurst"); break; default: break; } return sessionInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); return chart; }
From source file:UserInterface.CommunityRuralHouseholdWorkArea.ShowChartJPanel.java
private void createChart1() { System.out.println("Inside create chart fucntion"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(" Amount Distribution (Appliance Wise) ", // chart title "Appliance", // domain axis label "Amount", // range axis label createDataset(), // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/* ww w .ja va 2 s . co m*/ ChartPanel chart1 = new ChartPanel(chart); chartPanel1.removeAll(); chartPanel1.add(chart1, BorderLayout.CENTER); chartPanel1.validate(); }
From source file:edu.indiana.htrc.visual.HTRCBarChartDrawer.java
@Override public File draw() { System.out.println("draw bar!!!!!!!!!!!!!"); DefaultCategoryDataset bar_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");*/ Set<String> key_set = input_map.keySet(); Iterator<String> iter = key_set.iterator(); while (iter.hasNext()) { String key = iter.next(); int value = input_map.get(key); bar_dataset.setValue(value, dataset_label, key); }//from w ww.j av a2s . c om JFreeChart chart = null; if (is3D) { chart = ChartFactory.createBarChart3D(chart_name, x_axis_label, y_axis_label, bar_dataset, PlotOrientation.VERTICAL, true, true, false); } else { chart = ChartFactory.createBarChart(chart_name, x_axis_label, y_axis_label, bar_dataset, PlotOrientation.VERTICAL, true, true, false); } CategoryPlot p = chart.getCategoryPlot(); /* NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());*/ BarRenderer renderer = (BarRenderer) p.getRenderer(); DecimalFormat decimalformat1 = new DecimalFormat("##"); StandardCategoryItemLabelGenerator label_generator = new StandardCategoryItemLabelGenerator("{2}", decimalformat1); renderer.setItemLabelGenerator(label_generator); final ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0/* -Math.PI / 2.0*/ ); renderer.setPositiveItemLabelPosition(pos); final CategoryAxis domainAxis = p.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); renderer.setMaximumBarWidth(.15); renderer.setItemLabelsVisible(true); chart.getCategoryPlot().setRenderer(renderer); File img = new File("../webapps/HTRC-UI-AuditAnalyzer/images/" + System.currentTimeMillis() + ".jpg"); try { ChartUtilities.saveChartAsJPEG(img, chart, 1400, 600); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } return img; }
From source file:Controller.Movimientos.ControllerMovimientos.java
@Override public void actionPerformed(ActionEvent e) { switch (Actions.valueOf(e.getActionCommand())) { case btn_home: this.v.pnl_Main.removeAll(); this.v.pnl_Main.add(this.v.SplitPane1, BorderLayout.CENTER); this.v.pnl_Main.setVisible(false); this.v.pnl_Main.setVisible(true); break;// w ww . j a va2s . c o m case btn_ventasMovi: this.v.pnl_contenedorDerechoMovimientos.removeAll(); this.v.pnl_contenedorDerechoMovimientos.add(this.v.pnl_contenedorDerecho, BorderLayout.CENTER); this.v.pnl_contenedorDerechoMovimientos.setVisible(false); this.v.pnl_contenedorDerechoMovimientos.setVisible(true); DefaultCategoryDataset b = new DefaultCategoryDataset(); b.setValue(mm.getRecordEnero(), "Ventas", "Ene"); b.setValue(mm.getRecordFebrero(), "Ventas", "Feb"); b.setValue(mm.getRecordMarzo(), "Ventas", "Mar"); b.setValue(mm.getRecordAbril(), "Ventas", "Abr"); b.setValue(mm.getRecordMayo(), "Ventas", "May"); b.setValue(mm.getRecordJunio(), "Ventas", "Jun"); b.setValue(mm.getRecordJulio(), "Ventas", "Jul"); b.setValue(mm.getRecordAgosto(), "Ventas", "Ago"); b.setValue(mm.getRecordSeptiembre(), "Ventas", "Sep"); b.setValue(mm.getRecordOctubre(), "Ventas", "Oct"); b.setValue(mm.getRecordNoviembre(), "Ventas", "Nov"); b.setValue(mm.getRecordNoviembre(), "Ventas", "Dic"); JFreeChart grafica = ChartFactory.createBarChart("Ventas", "Meses", "Numero de ventas", b, PlotOrientation.VERTICAL, false, true, false); CategoryPlot graficaPlot = grafica.getCategoryPlot(); graficaPlot.setRangeGridlinePaint(Color.BLUE); ChartPanel barPanel = new ChartPanel(grafica); this.v.pnl_mostrarGrafica.removeAll(); this.v.pnl_mostrarGrafica.add(barPanel, BorderLayout.CENTER); this.v.pnl_mostrarGrafica.setVisible(false); this.v.pnl_mostrarGrafica.setVisible(true); mostrarFilechooser(); break; case btn_empleMovi: this.v.pnl_contenedorDerechoMovimientos.removeAll(); this.v.pnl_contenedorDerechoMovimientos.add(this.v.pnl_contenedorDerecho, BorderLayout.CENTER); this.v.pnl_contenedorDerechoMovimientos.setVisible(false); this.v.pnl_contenedorDerechoMovimientos.setVisible(true); DefaultCategoryDataset bE = new DefaultCategoryDataset(); Iterator it; it = mm.getCrews().iterator(); while (it.hasNext()) { Crew c = (Crew) it.next(); System.out.println("" + c.getEmail().toString()); bE.setValue(mm.getConexionesCount(c.getEmail().toString()), c.getEmail().toString(), c.getEmail().toString()); } JFreeChart graficaEmpleado = ChartFactory.createBarChart("Conexiones", "Meses", "Numero de ventas", bE, PlotOrientation.VERTICAL, false, true, false); CategoryPlot graficaPlotEmpleado = graficaEmpleado.getCategoryPlot(); graficaPlotEmpleado.setRangeGridlinePaint(Color.BLUE); ChartPanel barPanelEmpleado = new ChartPanel(graficaEmpleado); this.v.pnl_mostrarGrafica.removeAll(); this.v.pnl_mostrarGrafica.add(barPanelEmpleado, BorderLayout.CENTER); this.v.pnl_mostrarGrafica.setVisible(false); this.v.pnl_mostrarGrafica.setVisible(true); mostrarFilechooser(); break; case btn_productoMovi: this.v.pnl_contenedorDerechoMovimientos.removeAll(); this.v.pnl_contenedorDerechoMovimientos.add(this.v.pnl_contenedorDerecho, BorderLayout.CENTER); this.v.pnl_contenedorDerechoMovimientos.setVisible(false); this.v.pnl_contenedorDerechoMovimientos.setVisible(true); DefaultCategoryDataset bP = new DefaultCategoryDataset(); Iterator itP; itP = mm.getProducts().iterator(); while (itP.hasNext()) { Product p = (Product) itP.next(); System.out.println("" + p.getName()); bP.setValue(mm.getProductCount(p.getName().toString()), p.getName().toString(), p.getName().toString()); } JFreeChart graficaProducto = ChartFactory.createBarChart("Productos Vendidos", "Productos", "Ventas", bP, PlotOrientation.HORIZONTAL, false, true, false); CategoryPlot graficaPlotProducto = graficaProducto.getCategoryPlot(); graficaPlotProducto.setRangeGridlinePaint(Color.BLUE); ChartPanel barPanelProducto = new ChartPanel(graficaProducto); this.v.pnl_mostrarGrafica.removeAll(); this.v.pnl_mostrarGrafica.add(barPanelProducto, BorderLayout.CENTER); this.v.pnl_mostrarGrafica.setVisible(false); this.v.pnl_mostrarGrafica.setVisible(true); mostrarFilechooser(); break; case btn_configMovimientos: break; case btn_abrirFilechooser: break; case btn_informe: this.pdf.generateInforme(); break; } }
From source file:org.jfree.chart.demo.BarChartDemo4.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(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, true, // 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... final CategoryPlot plot = chart.getCategoryPlot(); // 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.setMaxBarWidth(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); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }