List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java
public JFreeChart getChartForPlate(PlateImpl plate) { IntensityMatrixImpl intensityMatrix = dataManager.getIntensityMatrix(); List<Injection> injections = intensityMatrix.getInjectionsByPlate().get(plate); DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (Injection one : injections) { dataset.add(Arrays.asList(intensityMatrix.getColumn(one)).stream().map((o) -> ((Double) o)) .collect(Collectors.toList()), "Intensity", one.toString()); }/*from www .j a va 2s . com*/ JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(plate.toString(), "Injection", "Intensity", dataset, true); chart.getCategoryPlot().getDomainAxis() .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2)); return chart; }
From source file:org.jenkinsci.plugins.autozoil.graph.AutozoilGraph.java
/** * Creates a Autozoil trend graph//ww w . j a v a 2 s .c om * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); ColorPalette.apply(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo7.java
protected JFreeChart createLegend(CategoryDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );/*from w w w .j av a2s . c om*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setItemMargin(0.10); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 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); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); return chart; }
From source file:cheuk.licenseheaderchecker.resource.DataGraph.java
/** * Creates a trend graph//from w w w .j a va2s . com * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... //final LegendTitle legend = chart.getLegend(); //legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); // rangeAxis.setAutoRange(true); final StackedAreaRenderer renderer = new StackedAreaRenderer2(); plot.setRenderer(renderer); //renderer.setBaseStroke(new BasicStroke(2.0f)); //ColorPalette.apply(renderer); plot.setRenderer(renderer); renderer.setSeriesPaint(2, RED); renderer.setSeriesPaint(1, GRAY); renderer.setSeriesPaint(0, YELLOW); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:hudson.plugins.labeledgroupedtests.TrendGraph.java
protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*from ww w. ja v a 2 s . c o m*/ chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); // plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); if (key.getColor() != null) return key.getColor(); return super.getItemPaint(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getURL() + relativeUrl; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTipText(); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Skips. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:com.pusksesmas.form_statistik.statistik_diagnosa.java
private void tabelDataMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelDataMouseClicked if (vpil.getSelectedIndex() == 1) { int row = tabelData.getSelectedRow(); String namaPenyakit = (tabelData.getModel().getValueAt(row, 0)).toString(); String jan = (tabelData.getModel().getValueAt(row, 1)).toString(); String feb = (tabelData.getModel().getValueAt(row, 2)).toString(); String mar = (tabelData.getModel().getValueAt(row, 3)).toString(); String apr = (tabelData.getModel().getValueAt(row, 4)).toString(); String mei = (tabelData.getModel().getValueAt(row, 5)).toString(); String jun = (tabelData.getModel().getValueAt(row, 6)).toString(); String jul = (tabelData.getModel().getValueAt(row, 7)).toString(); String agus = (tabelData.getModel().getValueAt(row, 8)).toString(); String sept = (tabelData.getModel().getValueAt(row, 9)).toString(); String okt = (tabelData.getModel().getValueAt(row, 10)).toString(); String nov = (tabelData.getModel().getValueAt(row, 11)).toString(); String des = (tabelData.getModel().getValueAt(row, 12)).toString(); DefaultCategoryDataset pieDataset = new DefaultCategoryDataset(); // pieDataset.setValue("Diagnosa", new Integer(jan)); pieDataset.setValue(new Integer(jan), "", "Januari"); pieDataset.setValue(new Integer(feb), "", "Februari"); pieDataset.setValue(new Integer(mar), "", "Maret"); pieDataset.setValue(new Integer(apr), "", "April"); pieDataset.setValue(new Integer(mei), "", "Mei"); pieDataset.setValue(new Integer(jun), "", "Juni"); pieDataset.setValue(new Integer(jul), "", "Juli"); pieDataset.setValue(new Integer(agus), "", "Agustus"); pieDataset.setValue(new Integer(sept), "", "September"); pieDataset.setValue(new Integer(okt), "", "Oktober"); pieDataset.setValue(new Integer(nov), "", "November"); pieDataset.setValue(new Integer(des), "", "Desember"); JFreeChart chart = ChartFactory.createBarChart3D( "STATISTIK HASIL DIGNOSA\nNAMA PENYAKIT: " + namaPenyakit, "BULAN", "JUMLAH", (CategoryDataset) pieDataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.yellow); chart.getTitle().setPaint(Color.red); final CategoryPlot p = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) p.getRenderer(); DecimalFormat sdf = new DecimalFormat("#,##0"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", sdf)); p.setRenderer(renderer);//from w ww .j av a 2 s . com renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER)); renderer.setItemLabelsVisible(true); chart.getCategoryPlot().setRenderer(renderer); p.setRangeGridlinePaint(Color.blue); ChartFrame frame = new ChartFrame("barchart", chart); frame.setVisible(true); frame.setLocation(250, 100); frame.setSize(800, 600); } else if (vpil.getSelectedIndex() == 2) { int row = tabelData.getSelectedRow(); String jan = (tabelData.getModel().getValueAt(row, 1)).toString(); String feb = (tabelData.getModel().getValueAt(row, 2)).toString(); String mar = (tabelData.getModel().getValueAt(row, 3)).toString(); String apr = (tabelData.getModel().getValueAt(row, 4)).toString(); String mei = (tabelData.getModel().getValueAt(row, 5)).toString(); String jun = (tabelData.getModel().getValueAt(row, 6)).toString(); String jul = (tabelData.getModel().getValueAt(row, 7)).toString(); String agus = (tabelData.getModel().getValueAt(row, 8)).toString(); String sept = (tabelData.getModel().getValueAt(row, 9)).toString(); String okt = (tabelData.getModel().getValueAt(row, 10)).toString(); String nov = (tabelData.getModel().getValueAt(row, 11)).toString(); String des = (tabelData.getModel().getValueAt(row, 12)).toString(); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Januari", new Integer(jan)); pieDataset.setValue("Februari", new Integer(feb)); pieDataset.setValue("Maret", new Integer(mar)); pieDataset.setValue("April", new Integer(apr)); pieDataset.setValue("Mei", new Integer(mei)); pieDataset.setValue("Juni", new Integer(jun)); pieDataset.setValue("Juli", new Integer(jul)); pieDataset.setValue("Agustus", new Integer(agus)); pieDataset.setValue("September", new Integer(sept)); pieDataset.setValue("Oktober", new Integer(okt)); pieDataset.setValue("November", new Integer(nov)); pieDataset.setValue("Desember", new Integer(des)); JFreeChart chart = ChartFactory.createPieChart("STATISTIK HASIL DIGNOSA", pieDataset, true, true, true); // PiePlot3D P = (PiePlot3D)chart.getPlot(); PiePlot P = (PiePlot) chart.getPlot(); //P.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame frame = new ChartFrame("STATISTIK HASIL DIGNOSA", chart); frame.setVisible(true); frame.setLocation(250, 100); frame.setSize(800, 600); } else { } }
From source file:hudson.plugins.measurement_plots.Graph.java
protected org.jfree.chart.JFreeChart createGraph() { final org.jfree.data.category.CategoryDataset dataset = getDataSetBuilder().build(); final org.jfree.chart.JFreeChart chart = org.jfree.chart.ChartFactory.createStackedAreaChart(title, // chart title null, // unused null, // range axis label dataset, // data org.jfree.chart.plot.PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );//from w w w . j ava2 s. co m chart.setBackgroundPaint(java.awt.Color.white); final org.jfree.chart.plot.CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); // plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(java.awt.Color.black); org.jfree.chart.axis.CategoryAxis domainAxis = new hudson.util.ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(org.jfree.chart.axis.CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final org.jfree.chart.axis.NumberAxis rangeAxis = (org.jfree.chart.axis.NumberAxis) plot.getRangeAxis(); hudson.util.ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(org.jfree.chart.axis.NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); org.jfree.chart.renderer.category.StackedAreaRenderer areaRenderer = new hudson.util.StackedAreaRenderer2() { @Override public java.awt.Paint getItemPaint(int row, int column) { GraphLabel key = (GraphLabel) dataset.getColumnKey(column); if (key.getColor() != null) { return key.getColor(); } return super.getItemPaint(row, column); } @Override public String generateURL(org.jfree.data.category.CategoryDataset dataset, int row, int column) { GraphLabel label = (GraphLabel) dataset.getColumnKey(column); return label.getUrl(); } @Override public String generateToolTip(org.jfree.data.category.CategoryDataset dataset, int row, int column) { GraphLabel label = (GraphLabel) dataset.getColumnKey(column); return label.getToolTip(); } }; plot.setRenderer(areaRenderer); areaRenderer.setSeriesPaint(2, hudson.util.ColorPalette.BLUE); // crop extra space around the graph plot.setInsets(new org.jfree.ui.RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:view.statistics.RequestStatsAndPrediction.java
private void predictButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_predictButtonActionPerformed int year = yearChooser.getYear(); int month = monthChooser.getMonth() + 1; int currentYear = Calendar.getInstance().get(Calendar.YEAR); int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1; int data[][] = null; try {/*w ww. j a v a 2 s . co m*/ data = sdcontroller.getYearlyRequestCountsOf(month); } catch (ClassNotFoundException ex) { } catch (SQLException ex) { } if (year >= currentYear && month >= currentMonth) { try { predictText.setText(Predictions.getPredictedRequestsOf(year, month) + ""); } catch (ClassNotFoundException ex) { Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(this, "Predictions available only for future months. Only the graph will be drawn", "Error", JOptionPane.ERROR_MESSAGE); predictText.setText("Invalid input!"); } //if (data != null) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if (data != null) { for (int i = 0; i < data[0].length; i++) { dataset.setValue(data[1][i], "Year", data[0][i] + ""); } } JFreeChart chart = ChartFactory.createLineChart3D( "Yearly Blood Request Count For The Month of " + getMontName(month + ""), "Year", "Request Count", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new java.awt.Dimension(200, 350)); chartAreaPanel.setLayout(new GridLayout()); chartAreaPanel.removeAll(); chartAreaPanel.revalidate(); chartAreaPanel.add(panel); chartAreaPanel.repaint(); this.repaint(); //} }
From source file:edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo1.java
/** * Creates a sample chart./* w ww . j av a 2 s . c om*/ * * @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 = 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:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { calcMeans();/*from w w w.j a va2s. c o m*/ calcAvgRulesBySeed(); // Create JFreeChart Dataset DefaultCategoryDataset dataset = new DefaultCategoryDataset(); HashMap<String, Double> measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue(); for (Map.Entry<String, Double> measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); Double measureValue = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length() - 1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.addValue(measureValue, aName, measureName); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart barChart = ChartFactory.createBarChart("Assotiation Rules Measures", measureName, measureName, dataset, PlotOrientation.VERTICAL, true, true, false); StandardChartTheme.createLegacyTheme().apply(barChart); CategoryItemRenderer renderer = barChart.getCategoryPlot().getRenderer(); // Black and White int numItems = algorithmMeasures.size(); for (int i = 0; i < numItems; i++) { Color color = Color.DARK_GRAY; if (i % 2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File BarChart = new File(outName + "_" + measureName + "_barchart.jpg"); ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); barChart.draw(g2, r); File BarChartSVG = new File(outName + "_" + measureName + "_barchart.svg"); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } } /* for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); HashMap<String, Double> measures = entry.getValue(); for (Map.Entry<String, Double> entry1 : measures.entrySet()) { String measureName = entry1.getKey(); Double measureValue = entry1.getValue(); dataset.addValue(measureValue, alg, measureName); } } */ }