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:plugins.tutorial.chart.ChartTutorial1.java
/** * Creates a sample chart.//w ww . j ava 2 s . c o m * * @param dataset * the dataset. * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", // chart title "Category", // domain axis label "Value", // 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:com.att.aro.main.FileTypesChartPanel.java
/** * Initializes the File Type chart.// w w w. j a va2s .c om */ private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("chart.filetype.title"), null, rb.getString("simple.percent"), null, 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(.5f); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); 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)); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { FileTypeSummary summary = content.get(column); return MessageFormat.format(rb.getString("chart.filetype.tooltip"), NumberFormat.getIntegerInstance().format(summary.getBytes())); } }); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); BarPainter painter = new StandardBarPainter(); renderer.setBarPainter(painter); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(0.1); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, 400, ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:com.xilinx.ultrascale.gui.BarChartsEth.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 www. j a va 2 s .c om 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:utils.Graficos_old.java
public JFreeChart GraficoBarras(List<CarCapContas> pagar, List<CarCapContas> receber, String titulo) { String[] meses = { "Janeiro", "Fevereiro", "Maro", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int indice = 0; for (CarCapContas i : pagar) { dataset.addValue(i.getContaValorTotal(), "Contas a pagar", meses[indice]); indice++;//from w w w. ja va2 s .c om } indice = 0; for (CarCapContas i : receber) { dataset.addValue(i.getContaValorTotal(), "Contas a receber", meses[indice]); indice++; } JFreeChart barChart = ChartFactory.createBarChart(titulo, "Ms", "Valor total", dataset, PlotOrientation.VERTICAL, true, true, false); return barChart; }
From source file:eu.planets_project.tb.impl.chart.ExperimentExecutionCharts.java
public JFreeChart createXYChart(String expId) { ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance(); long eid = Long.parseLong(expId); log.info("Building experiment chart for eid = " + eid); Experiment exp = edao.findExperiment(eid); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final String expName = exp.getExperimentSetup().getBasicProperties().getExperimentName(); List<Boolean> success = new ArrayList<Boolean>(); for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) { int i = 1; for (ExecutionRecordImpl exr : batch.getRuns()) { //log.info("Found Record... "+exr+" stages: "+exr.getStages()); if (exr != null && exr.getStages() != null) { // Look up the object, so we can get the name. DigitalObjectRefBean dh = new DataHandlerImpl().get(exr.getDigitalObjectReferenceCopy()); String dobName = "Object " + i; if (dh != null) dobName = dh.getName(); for (ExecutionStageRecordImpl exsr : exr.getStages()) { Double time = exsr.getDoubleMeasurement(TecRegMockup.PROP_SERVICE_TIME); // Look for timing: if (time != null) { dataset.addValue(time, expName, dobName); if (exsr.isMarkedAsSuccessful()) { success.add(Boolean.TRUE); } else { success.add(Boolean.FALSE); }/*www . ja v a2 s . c o m*/ } } } // Increment, for the next run. i++; } } // Create the chart. JFreeChart chart = ChartFactory.createBarChart(null, "Digital Object", "Time [s]", dataset, PlotOrientation.VERTICAL, true, true, false); // 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()); Paint[] customColours = new Paint[success.size()]; for (int i = 0; i < success.size(); i++) { Boolean b = success.get(i); if (Boolean.TRUE.equals(b)) { customColours[i] = Color.GREEN; } else { customColours[i] = Color.RED; } } CategoryItemRenderer renderer = new CustomRenderer(customColours); // disable bar outlines... //final BarRenderer renderer = (BarRenderer) plot.getRenderer(); //renderer.setDrawBarOutline(false); plot.setRenderer(renderer); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.pink); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); // Set the tooltips... renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp", "series", "section")); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo3.java
/** * Creates a sample chart./* w w w .j a v a2 s . c o m*/ * * @param dataset the dataset. * * @return a sample chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation !legendPanelOn, // include legend true, false); chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA!"); CategoryItemRenderer renderer = new CustomBarRenderer(new Paint[] { Color.red, Color.blue, Color.green, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setBasePositiveItemLabelPosition(p); plot.setRenderer(renderer); CategoryMarker marker = new CategoryMarker("Category 3"); marker.setLabel("Special"); marker.setPaint(new Color(0xDD, 0xFF, 0xDD, 0x80)); marker.setAlpha(0.5f); marker.setLabelAnchor(RectangleAnchor.TOP_LEFT); marker.setLabelTextAnchor(TextAnchor.TOP_LEFT); marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT); plot.addDomainMarker(marker, Layer.BACKGROUND); // change the margin at the top of the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); BarRenderer seriesRenderer = (BarRenderer) plot.getRenderer(); seriesRenderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:eu.delving.stats.ChartHelper.java
private static JFreeChart createWordCountChart(Stats.ValueStats valueStats, Path path, String name) { if (valueStats.wordCounts == null) return null; List<Stats.Counter> sorted = sort(valueStats.wordCounts.counterMap.values(), MAX_BAR_CHART_SIZE, valueStats.total);//from w w w . j av a2 s. c om DefaultCategoryDataset data = new DefaultCategoryDataset(); for (Stats.Counter counter : sorted) data.addValue(counter.count, "Count", counter.value); JFreeChart chart = ChartFactory.createBarChart(String.format("Word count per occurrence in %s", name), "Number of Words", "Record count", data, PlotOrientation.VERTICAL, false, true, false); chart.addSubtitle(new TextTitle(path.toString())); return finishBarChart(chart, new Color(218, 112, 214)); }
From source file:cgpanalyser.gui.EvoInfoChart.java
private JFreeChart createChart(final CategoryDataset dataset, long[] gateFuncsCounts, GateFuctionsAll gateFuncsAll) {//from w ww.ja va2 s . c o m final JFreeChart chart = ChartFactory.createBarChart(null, "Function", "Usage", dataset, PlotOrientation.VERTICAL, false, true, false); //match colors of bars to colors in function file (or black if not specified) Paint[] colors = new Paint[gateFuncsCounts.length]; for (byte i = 0; i < colors.length; i++) { colors[i] = gateFuncsAll.getColorIfAvailable(i); } final CategoryItemRenderer renderer = new CustomRenderer(colors); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRenderer(renderer); ((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter()); //no gradient CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); //CategoryAxis axis = plot.getDomainAxis(); //NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); //set x axis tick //xAxis.setVerticalTickLabels(true); //set x axis text rotation return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo9.java
/** * Creates a sample chart./*from ww w. java 2s . c om*/ * * @param dataset the dataset. * * @return a sample chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation !legendPanelOn, // include legend true, false); TextTitle title = chart.getTitle(); title.setBorder(0, 0, 1, 0); title.setBackgroundPaint(new GradientPaint(0f, 0f, Color.red, 350f, 0f, Color.white, true)); title.setExpandToFitSpace(true); chart.setBackgroundPaint(new GradientPaint(0f, 0f, Color.yellow, 350f, 0f, Color.white, true)); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA!"); plot.setBackgroundPaint(null); plot.setInsets(new RectangleInsets(10, 5, 5, 5)); plot.setOutlinePaint(Color.black); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlineStroke(new BasicStroke(1.0f)); Paint[] colors = createPaint(); CustomBarRenderer renderer = new CustomBarRenderer(colors); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(renderer); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); // change the margin at the top of the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // rangeAxis.setRange(0.0, 800.0); rangeAxis.setTickMarkPaint(Color.black); setCategorySummary(dataset); return chart; }
From source file:com.xilinx.ultrascale.gui.PowerChart.java
private void makeChart() { dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("", "Time Interval", "", dataset, PlotOrientation.HORIZONTAL, true, true, false);/*from ww w . j a v a2 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(6); axis.setAutoRange(true); axis.setLowerMargin(0); axis.setUpperMargin(.40); // TickUnits tickUnits = new TickUnits(); // tickUnits.add(new NumberTickUnit(1)); // 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(0x2e, 0x90, 0x18));//(0x17, 0x7b, 0x7c)); renderer.setSeriesPaint(1, new Color(0x12, 0x45, 0x73));//(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(); }