List of usage examples for org.jfree.chart ChartFactory createBarChart3D
public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:giaodien.tongquan.TongQuan.java
public void GraphTongDoanhThu() throws SQLException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); PreparedStatement doanhthu = con.prepareStatement( "SELECT sum(TONGTIEN) as DoanhThu, day(date(THOIGIAN)) As Ngay FROM shop.hoadonbanhang where month(date(THOIGIAN))= " + thang + " group by day(date(THOIGIAN)) "); ResultSet rsdoanhthu = doanhthu.executeQuery(); while (rsdoanhthu.next()) { doanhthutrongngay = rsdoanhthu.getInt("DoanhThu"); ngay = rsdoanhthu.getString("Ngay"); dataset.setValue(doanhthutrongngay, "", ngay); }// ww w. j a va 2s .c om JFreeChart chart = ChartFactory.createBarChart3D(null, null, "VN?", dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot catePlot = chart.getCategoryPlot(); catePlot.setRangeGridlinePaint(Color.BLACK); //set bar chart color ((BarRenderer) catePlot.getRenderer()).setBarPainter(new StandardBarPainter()); BarRenderer r = (BarRenderer) chart.getCategoryPlot().getRenderer(); r.setSeriesPaint(0, Color.GREEN); ChartPanel chartpanel = new ChartPanel(chart); graph.removeAll(); graph.add(chartpanel, BorderLayout.CENTER); graph.setBackground(getBackground()); graph.validate(); }
From source file:org.bench4Q.console.ui.section.S_LengthSection.java
/** * @return/*from w w w . j a va 2 s. c o m*/ * @throws IOException */ public JPanel drawSessionPic() throws IOException { CategoryDataset dataset = getDataSet(); JFreeChart chart = ChartFactory.createBarChart3D("Session", "Session type", "Session number", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.1); domainAxis.setUpperMargin(0.1); domainAxis.setCategoryLabelPositionOffset(10); domainAxis.setCategoryMargin(0.2); org.jfree.chart.axis.ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.1); org.jfree.chart.renderer.category.BarRenderer3D renderer; renderer = new org.jfree.chart.renderer.category.BarRenderer3D(); renderer.setBaseOutlinePaint(Color.red); renderer.setSeriesPaint(0, new Color(0, 255, 255)); renderer.setSeriesOutlinePaint(0, Color.BLACK); renderer.setSeriesPaint(1, new Color(0, 255, 0)); renderer.setSeriesOutlinePaint(1, Color.red); renderer.setItemMargin(0.1); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("", Font.BOLD, 12)); renderer.setItemLabelPaint(Color.black); renderer.setItemLabelsVisible(true); plot.setRenderer(renderer); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setBackgroundPaint(Color.WHITE); return new ChartPanel(chart); }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of a Comparative Response Model * Histogram./* ww w.ja v a 2 s .c om*/ * * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param dataBefore * The array of values before the response. * @param dataAfter * The array of values after the response. * @return a chart panel with the graphical representation. */ public static ChartPanel createDailyResponseHistogram(String title, String x, String y, double[] dataBefore, double[] dataAfter) { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < dataBefore.length; i++) { dataset.addValue(dataBefore[i], "Basic Scheme", "" + i + ""); if (i < dataAfter.length) dataset.addValue(dataAfter[i], "New Scheme", "" + i + ""); else dataset.addValue(0, "New Scheme", "" + i + ""); } JFreeChart chart = ChartFactory.createBarChart3D(title, // chart title x, // domain axis label y, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(1.0f); // left align the category labels... final CategoryAxis axis = plot.getDomainAxis(); final CategoryLabelPositions p = axis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f); axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); return new ChartPanel(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 www .j av a 2 s .co 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:com.sun.portal.os.portlets.PortletChartUtilities.java
private static JFreeChart createChart(ResourceRequest request) { JFreeChart chart = null;// ww w . j a v a 2s. c om try { PortletPreferences prefs = request.getPreferences(); if (prefs == null) throw new NoPreferredDbSetException("Preferences not passed in from portlet"); String type = prefs.getValue(Constants.PREF_CHART_TYPE, PIE_CHART); debugMessage("Chart type :" + type); if (type.equals(PIE_CHART)) { String sql = prefs.getValue(Constants.PREF_PIE_CHART_SQL, DEFAULT_PIE_CHART_SQL); PieDataset data = (PieDataset) generatePieDataSet(getDatabaseConnection(request), sql); chart = ChartFactory.createPieChart("Pie Chart", data, true, true, false); } else if (type.equals(BAR_CHART)) { String sql = prefs.getValue(Constants.PREF_BAR_CHART_SQL, DEFAULT_BAR_CHART_SQL); JDBCCategoryDataset data = (JDBCCategoryDataset) generateBarChartDataSet( getDatabaseConnection(request), sql); chart = ChartFactory.createBarChart3D("Bar Chart", "Category", "Value", data, PlotOrientation.VERTICAL, true, true, false); } else if (type.equals(TIME_CHART)) { String sql = prefs.getValue(Constants.PREF_TIME_SERIES_SQL, DEFAULT_TIME_SERIES_SQL); JDBCXYDataset data = (JDBCXYDataset) generateXYDataSet(getDatabaseConnection(request), sql); chart = ChartFactory.createTimeSeriesChart("Time Series Chart", "Date", "Rate", data, true, true, false); } } catch (NoPreferredDbSetException npdbs) { npdbs.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return chart; }
From source file:org.bench4Q.console.ui.section.E_ErrorSection.java
private JPanel printErrorPic() throws IOException { CategoryDataset dataset = getDataSet(); JFreeChart chart = ChartFactory.createBarChart3D("Error", "Error type", "Error number", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.1);//from w w w .j av a2s.c om domainAxis.setUpperMargin(0.1); domainAxis.setCategoryLabelPositionOffset(10); domainAxis.setCategoryMargin(0.2); domainAxis.setCategoryLabelPositionOffset(10); org.jfree.chart.axis.ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.1); org.jfree.chart.renderer.category.BarRenderer3D renderer; renderer = new org.jfree.chart.renderer.category.BarRenderer3D(); renderer.setBaseOutlinePaint(Color.red); renderer.setSeriesPaint(0, new Color(0, 255, 255)); renderer.setSeriesOutlinePaint(0, Color.BLACK); renderer.setSeriesPaint(1, new Color(0, 255, 0)); renderer.setSeriesOutlinePaint(1, Color.red); renderer.setItemMargin(0.1); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("", Font.BOLD, 12)); renderer.setItemLabelPaint(Color.black); renderer.setItemLabelsVisible(true); plot.setRenderer(renderer); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setBackgroundPaint(Color.WHITE); return new ChartPanel(chart); }
From source file:org.getobjects.samples.HelloChart.Main.java
/** * This defines the direct action which can be invoked using:<pre> * /HelloThumbnail/wa/Main/chart?chs=128x128&chartType=p3</pre> * /*from w w w . j a v a 2 s . co m*/ * <p> * Note that the method returns a java.awt.BufferedImage. This will get * rendered to a GIF image by the GoDefaultRenderer. * (this method does not return a WOResponse, but it lets the Go machinery * deal with the image result object). * * @return a BufferedImage containing the scaled image */ public Object chartAction() { Dimension size = UGoogleChart.getDimensions(F("chs", "128x128"), null); String chartType = (String) F("cht", "p"); JFreeChart chart = null; if (chartType.equals("p")) { chart = ChartFactory.createPieChart((String) F("title", "Revenue Chart" /* default title */), this.getPieDataset(), UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } else if (chartType.equals("p3")) { chart = ChartFactory.createPieChart3D((String) F("title", "Revenue Chart" /* default title */), this.getPieDataset(), UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } else if (chartType.startsWith("b")) { // bhs, bvs (one bar with multiple values) // bhg, bvg (one bar for each row) PlotOrientation orientation = PlotOrientation.VERTICAL; if (chartType.startsWith("bh")) orientation = PlotOrientation.HORIZONTAL; if (chartType.endsWith("3")) { chart = ChartFactory.createBarChart3D((String) F("title", "Revenue Chart" /* default title */), (String) F("xlabel", "X-Axis"), (String) F("ylabel", "Y-Axis"), getCatDataSet(), orientation, UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } else { chart = ChartFactory.createBarChart((String) F("title", "Revenue Chart" /* default title */), (String) F("xlabel", "X-Axis"), (String) F("ylabel", "Y-Axis"), getRevCatDataSet(), orientation, UObject.boolValue(F("legend", true)) /* show legend */, UObject.boolValue(F("tooltips", true)) /* show tooltips */, false /* no URLs */); } } /* style the chart */ chart.setBorderVisible(true); //chart.setBorderPaint(new Paint(Color.blue)); Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue); chart.setBackgroundPaint(p); /* style the plot */ Plot plot = chart.getPlot(); plot.setBackgroundPaint(new Color(240, 240, 250)); /* add explosion for Pies */ if (plot instanceof PiePlot) { PiePlot pplot = (PiePlot) chart.getPlot(); pplot.setExplodePercent("Products", 0.30); // can be multiple explodes } /* create the image for HTTP delivery */ return chart.createBufferedImage(size.width, size.height); }
From source file:com.vectorprint.report.jfree.ChartBuilder.java
private void prepareChart(Dataset data, CHARTTYPE type) throws VectorPrintException { switch (type) { case AREA:/* w w w. j ava 2 s .c om*/ chart = ChartFactory.createAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case LINE: if (chart == null) { chart = ChartFactory.createLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case LINE3D: if (chart == null) { chart = ChartFactory.createLineChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR: if (chart == null) { chart = ChartFactory.createBarChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR3D: if (chart == null) { chart = ChartFactory.createBarChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof CategoryDataset) { CategoryDataset cd = (CategoryDataset) data; chart.getCategoryPlot().setDataset(cd); } else { throw new VectorPrintException("you should use CategoryDataset for this chart"); } break; case PIE: chart = ChartFactory.createPieChart(title, null, legend, tooltips, urls); case PIE3D: if (chart == null) { chart = ChartFactory.createPieChart3D(title, null, legend, tooltips, urls); } if (data instanceof PieDataset) { PieDataset pd = (PieDataset) data; PiePlot pp = (PiePlot) chart.getPlot(); pp.setDataset(pd); } else { throw new VectorPrintException("you should use PieDataset for this chart"); } break; case XYLINE: chart = ChartFactory.createXYLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case XYAREA: if (chart == null) { chart = ChartFactory.createXYAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof XYDataset) { XYDataset xy = (XYDataset) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use XYDataset for this chart"); } break; case TIME: chart = ChartFactory.createTimeSeriesChart(title, categoryLabel, valueLabel, null, legend, tooltips, urls); if (data instanceof TimeSeriesCollection) { TimeSeriesCollection xy = (TimeSeriesCollection) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use TimeSeriesCollection for this chart"); } break; default: throw new VectorPrintException("unsupported chart"); } chart.setAntiAlias(true); chart.setTextAntiAlias(true); }
From source file:org.bench4Q.console.ui.section.S_SummarizeSection.java
/** * @return//from www. ja v a2 s . c o m * @throws IOException */ public JPanel drawSessionPic() throws IOException { CategoryDataset dataset = getDataSet(); JFreeChart chart = ChartFactory.createBarChart3D("Session", "Session type", "Session number", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.1); domainAxis.setUpperMargin(0.1); domainAxis.setCategoryLabelPositionOffset(10); domainAxis.setCategoryMargin(0.2); org.jfree.chart.axis.ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.1); org.jfree.chart.renderer.category.BarRenderer3D renderer; renderer = new org.jfree.chart.renderer.category.BarRenderer3D(); renderer.setBaseOutlinePaint(Color.red); renderer.setSeriesPaint(0, new Color(0, 255, 255)); renderer.setSeriesOutlinePaint(0, Color.BLACK); renderer.setSeriesPaint(1, new Color(0, 255, 0)); renderer.setSeriesOutlinePaint(1, Color.red); renderer.setItemMargin(0.1); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("", Font.PLAIN, 12)); renderer.setItemLabelPaint(Color.black); renderer.setItemLabelsVisible(true); plot.setRenderer(renderer); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setBackgroundPaint(Color.WHITE); return new ChartPanel(chart); }
From source file:edu.ku.brc.stats.BarChartPanel.java
public synchronized void allResultsBack(final QueryResultsContainerIFace qrc) { // create a dataset... String cat = ""; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); java.util.List<Object> list = handler.getDataObjects(); for (int i = 0; i < list.size(); i++) { Object descObj = list.get(i++); Object valObj = list.get(i); if (descObj != null && valObj != null) { dataset.addValue(getInt(valObj), getString(descObj), cat); }//from w w w . j av a 2 s.c o m } list.clear(); // create the chart... JFreeChart jgChart = ChartFactory.createBarChart3D(title, // chart title xAxisTitle, // domain axis label yAxisTitle, // range axis label dataset, // data isVertical ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL, true, // include legend true, // tooltips? false // URLs? ); // create and display a frame... chartPanel = new org.jfree.chart.ChartPanel(jgChart, true, true, true, true, true); /*CustomColorBarChartRenderer ccbcr = new CustomColorBarChartRenderer() jgChart.getCategoryPlot().setRenderer(ccbcr); //Collection<LegendItem> items = jgChart.getCategoryPlot().getLegendItems(); for (int i=0;i<jgChart.getCategoryPlot().getLegendItems().getItemCount();i++) { LegendItem item = jgChart.getCategoryPlot().getLegendItems().get(i); item.setFillPaintTransformer(transformer) } //jgChart.getCategoryPlot().setRenderer(new CustomColorBarChartRenderer()); */ removeAll(); setLayout(new ChartLayoutManager(this)); add(chartPanel); validate(); doLayout(); repaint(); // TODO This is a kludge for now to get the BarChart to Paint Correctly UIRegistry.forceTopFrameRepaint(); }