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:edu.ucla.stat.SOCR.chart.demo.BarChartDemo8.java
/** * Creates a sample chart.//from w w w. j a v a2 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? ); 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); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.15); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); BarRenderer seriesRenderer = (BarRenderer) plot.getRenderer(); seriesRenderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo2.java
/** * Creates a sample chart./*from w w w . j a v a 2 s . c o m*/ * * @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.HORIZONTAL, // orientation !legendPanelOn, // include legend true, // tooltips? false // URLs? ); 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... LayeredBarRenderer renderer = new LayeredBarRenderer(); renderer.setDrawBarOutline(false); plot.setRenderer(renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder(SortOrder.DESCENDING); // 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()); setCategorySummary(dataset); return chart; }
From source file:com.itemanalysis.jmetrik.graph.barchart.BarChartPanel.java
public void setGraph() throws IllegalArgumentException { boolean hasGroupingVariable = false; if (command.getFreeOption("groupvar").hasValue()) { hasGroupingVariable = true;/*from ww w.j a v a 2s. c o m*/ } String name = command.getFreeOption("variable").getString(); String xLabel = name; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String yLabel = ""; if (command.getSelectOneOption("yaxis").isValueSelected("freq")) { yLabel = "Frequency"; } else { yLabel = "Percentage"; } if (command.getSelectOneOption("layout").isValueSelected("stacked")) { chart = ChartFactory.createStackedBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } else if (command.getSelectOneOption("view").isValueSelected("3D")) { chart = ChartFactory.createBarChart3D(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); } else { chart = ChartFactory.createBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); } String sub = ""; if (command.getFreeOption("subtitle").getString() != null) { sub = command.getFreeOption("subtitle").getString(); } TextTitle subtitle1 = new TextTitle(sub); chart.addSubtitle(subtitle1); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); if (command.getSelectOneOption("layout").isValueSelected("layered")) { LayeredBarRenderer renderer = new LayeredBarRenderer(); // renderer.setDrawBarOutline(false); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); } chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(BarChartPanel.this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); // plot.setForegroundAlpha(0.80f); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); this.setBackground(Color.WHITE); this.add(panel); }
From source file:Client.Gui.TeamBarChart.java
/** * Creates a sample chart.//from ww w . jav a 2 s .c om * * @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); 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; }
From source file:UserInterface.CommunityRuralHouseholdWorkArea.ShowChartJPanel.java
private void createChart2() { System.out.println("Inside create chart fucntion"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(" Cost Per Unit ", // chart title "Amount", // domain axis label "Kwh", // range axis label createDataset1(), // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from ww w. j a v a2s . com ChartPanel chart2 = new ChartPanel(chart); chartPanel2.removeAll(); chartPanel2.add(chart2, BorderLayout.CENTER); chartPanel2.validate(); }
From source file:org.eobjects.datacleaner.widgets.result.PatternFinderResultSwingRendererCrosstabDelegate.java
protected void displayChart(DCTable table, DisplayChartCallback displayChartCallback) { final int rowCount = table.getRowCount(); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < rowCount; i++) { final Object expressionObject = table.getValueAt(i, 0); final String expression = extractString(expressionObject); final Object countObject = table.getValueAt(i, 1); final String countString = extractString(countObject); final int count = Integer.parseInt(countString); dataset.addValue(count, expression, ""); }/*from w ww .j a v a2 s . co m*/ JFreeChart chart = ChartFactory.createBarChart("", "", "Match count", dataset, PlotOrientation.VERTICAL, true, true, false); ChartUtils.applyStyles(chart); displayChartCallback.displayChart(new ChartPanel(chart)); }
From source file:org.jfree.chart.demo.ItemLabelDemo1.java
/** * Creates a sample chart.//from w w w . ja v a 2s.co m * * @param dataset * the dataset. * @return the chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Item Label Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setLabelGenerator(new LabelGenerator(50.0)); renderer.setItemLabelsVisible(true); return chart; }
From source file:org.datacleaner.widgets.result.PatternFinderResultSwingRendererCrosstabDelegate.java
protected void displayChart(DCTable table, DisplayChartCallback displayChartCallback) { final int rowCount = table.getRowCount(); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < rowCount; i++) { final Object expressionObject = table.getValueAt(i, 0); final String expression = extractString(expressionObject); final Object countObject = table.getValueAt(i, 1); final String countString = extractString(countObject); final int count = Integer.parseInt(countString); dataset.addValue(count, expression, ""); }//from www . java2 s.co m // only show legend if there are not too many patterns final boolean showLegend = dataset.getRowCount() < 25; JFreeChart chart = ChartFactory.createBarChart("", "", "Match count", dataset, PlotOrientation.VERTICAL, showLegend, true, false); ChartUtils.applyStyles(chart); final ChartPanel chartPanel = ChartUtils.createPanel(chart, true); displayChartCallback.displayChart(chartPanel); }
From source file:com.xilinx.kintex7.DMABarChart.java
private void makeChart() { dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("", "Time Interval", "Throughput (Gbps)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(bg);/*from w w w . jav a 2 s .c o m*/ TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15)); ttitle.setPaint(Color.WHITE); chart.setTitle(ttitle); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ValueAxis axis = plot.getRangeAxis(); axis.setUpperBound(30.0); axis.setLowerBound(0.0); axis.setTickLabelPaint(new Color(185, 185, 185)); axis.setLabelPaint(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(0, 0, 0x80)); renderer.setSeriesPaint(1, new Color(0, 0x80, 0xff)); renderer.setSeriesPaint(2, new Color(0xa2, 0x45, 0x73)); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000"))); //renderer.setMaximumBarWidth(0.05); addDummy(); }
From source file:com.xilinx.virtex7.DMABarChart.java
private void makeChart() { dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("", "Time Interval", "Throughput (Gbps)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(bg);/*from w ww. j a va 2 s .com*/ TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15)); ttitle.setPaint(Color.WHITE); chart.setTitle(ttitle); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ValueAxis axis = plot.getRangeAxis(); axis.setUpperBound(64.0); axis.setLowerBound(0.0); axis.setTickLabelPaint(new Color(185, 185, 185)); axis.setLabelPaint(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(0, 0, 0x80)); renderer.setSeriesPaint(1, new Color(0, 0x80, 0xff)); renderer.setSeriesPaint(2, new Color(0xa2, 0x45, 0x73)); renderer.setSeriesPaint(3, new Color(0x40, 0xa1, 0xff)); renderer.setSeriesPaint(4, new Color(0xa1, 0x60, 0x98)); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000"))); //renderer.setMaximumBarWidth(0.05); addDummy(); }