List of usage examples for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset
public DefaultCategoryDataset()
From source file:edu.cuny.cat.ui.ProfitPlotPanel.java
public ProfitPlotPanel() { shoutSet = Collections.synchronizedSet(new HashSet<Shout>()); registry = GameController.getInstance().getRegistry(); setTitledBorder("Income and Expenses"); dataset = new DefaultCategoryDataset(); final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL, true, true, false);//from w w w .j a v a 2s .c om // chart.setAntiAlias(false); chart.setBackgroundPaint(getBackground()); final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); final StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(); UIUtils.setDefaultBarRendererStyle(stackedbarrenderer); stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); stackedbarrenderer.setBaseItemLabelsVisible(true); final ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); }
From source file:datavis.Gui.java
private void initGraphs(DataList dataset) { //Initialize the GUI with default, blank sample graphs //That serve as place holders for that actual content //Create Pie Chart PieChart samplePie = new PieChart("Sample Data"); samplePie.addData("Default Value", 1.0); JFreeChart chart = samplePie.getChartPanel(); //Add chart to GUI javax.swing.JPanel chartPanel = new ChartPanel(chart); chartPanel.setSize(jPanel1.getSize()); jPanel1.add(chartPanel);//from ww w.jav a2s . c om jPanel1.getParent().validate(); //Create Line graph DefaultCategoryDataset sampleLine = new DefaultCategoryDataset(); sampleLine.setValue(1.0, "sample Data", "Sample Data"); JFreeChart chart2 = ChartFactory.createLineChart("Sample Data", "Sample", "Sample", sampleLine); //Add chart to GUI javax.swing.JPanel chartPanel2 = new ChartPanel(chart2); chartPanel2.setSize(jPanel2.getSize()); jPanel2.add(chartPanel2); jPanel2.getParent().validate(); //Create bar graph DefaultCategoryDataset sampleBar = new DefaultCategoryDataset(); sampleLine.setValue(1.0, "sample Data", "Sample Data"); JFreeChart chart3 = ChartFactory.createBarChart("Sample Data", "Sample", "Sample", sampleBar); //Add chart to GUI javax.swing.JPanel chartPanel3 = new ChartPanel(chart3); chartPanel3.setSize(jPanel3.getSize()); jPanel3.add(chartPanel3); jPanel3.getParent().validate(); //Set the author information to the info box jTextArea2.setText(displayDevelopers); }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeBarTimeChartData.java
@Override public JFreeChart getJFreeChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double counts[] = ds.getCounts(); String legends[] = ds.getLegends(); int max_len = 0; for (int i = 0; i < ds.getNumSets(); i++) { if (legends != null && legends.length > i) { dataset.addValue(new Double(counts[i]), "Series-1", legends[i]); int leg_len = legends[i].length(); if (leg_len > max_len) { max_len = leg_len;//from w ww .j a v a 2 s .c om } //System.out.println(legends[i] + counts[i]); } else { dataset.addValue(new Double(counts[i]), "Series-1", Integer.toString(i)); } } CategoryDataset data = dataset; JFreeChart chart = ChartFactory.createBarChart(title, null, quantity, data, PlotOrientation.VERTICAL, false, // include legends false, // tooltips false // urls ); CategoryPlot categoryPlot = chart.getCategoryPlot(); CategoryAxis axis = categoryPlot.getDomainAxis(); if (max_len > 8 || ds.getNumSets() > 16 || (max_len * ds.getNumSets()) > 50) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); } Font tickLabelFont = axis.getTickLabelFont(); if (ds.getNumSets() > 24) { axis.setTickLabelFont(tickLabelFont.deriveFont(tickLabelFont.getSize() - 2.0F)); } Font labelFont = axis.getLabelFont(); axis.setMaximumCategoryLabelLines(3); //axis.setLabelFont(labelFont.d); // axis.setLabel("Pingu"); This works so we can modify return chart; }
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); }/*w w w . java 2 s. com*/ } } } // 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:net.nosleep.superanalyzer.analysis.views.MostPlayedDGView.java
private void createPanel() { _decadeDataset = new DefaultCategoryDataset(); _genreDataset = new DefaultCategoryDataset(); _decadeChart = createChart(Misc.getString("MOST_PLAYED_DECADES"), "", _decadeDataset); _genreChart = createChart(Misc.getString("MOST_PLAYED_GENRES"), "", _genreDataset); refreshDataset();//from w w w .j av a 2 s . com _decadeChartPanel = new ChartPanel(_decadeChart); _genreChartPanel = new ChartPanel(_genreChart); }
From source file:graficos.GraficoBarras.java
private void inicializar() { sub_titulos = new Vector<TextTitle>(); cjto_datos = new DefaultCategoryDataset(); grafico = crearGrafico(cjto_datos);// w ww .java 2 s.c om panel_grafico = new ChartPanel(grafico); panel_grafico.setFillZoomRectangle(true); panel_grafico.setMouseWheelEnabled(true); panel_grafico.setPreferredSize(new Dimension(500, 270)); }
From source file:jenkins.plugins.livingdoc.chart.ProjectSummaryChart.java
private DefaultCategoryDataset aggregateDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SummaryBuildReportBean summary : summaries) { Statistics stats = summary.getBuildSummary().getStatistics(); String label = String.format("#%d", summary.getBuildId()); int failureCount = stats.exceptionCount() + stats.wrongCount(); dataset.addValue(stats.rightCount(), SUCCESS_SERIES_NAME, label); dataset.addValue(failureCount, FAILURES_SERIES_NAME, label); adjustUpperBound(stats);/* w ww. j a v a2 s .com*/ adjustLowerBound(stats, failureCount); } return dataset; }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByHostingServer.java
/** * {@inheritDoc}/*from w w w. j a va 2s . c o m*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { if (!UserIdentityUtil.hasGlobalAdministratorRole(currentuser, "INVOCATIONS_BY_HOSTING_SERVER", classification, ctx)) { data.append("<h2>Access for " + GetDisplayName() + " was denied for non-global admin users</h2>"); return; } int itemcount = 0; Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents Web Application Server utilization (host) by invocations.<br />"); data.append("<table class=\"table table-hover\"><tr><th>Host</th><th>Invocations</th></tr>"); List<String> dcs = new ArrayList<String>(); try { cmd = con.prepareStatement("select hostingsource from RawData group by hostingsource;"); rs = cmd.executeQuery(); while (rs.next()) { dcs.add(rs.getString(1)); } } catch (Exception ex) { } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } try { itemcount = dcs.size(); for (int i = 0; i < dcs.size(); i++) { data.append("<tr><td>").append(Utility.encodeHTML(dcs.get(i))).append("</td><td>"); int success = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where hostingsource=? and UTCdatetime > ? and UTCdatetime < ?;"); cmd.setString(1, dcs.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { success = rs.getInt(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append(success + "").append("</td></tr>"); set.addValue(success, dcs.get(i), dcs.get(i)); } } catch (Exception ex) { log.log(Level.ERROR, "Error generating chart information.", ex); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Hosting Servers", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(itemcount)); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:com.googlecode.jchav.chart.MinMeanMaxChart.java
/** * Construct a new chart to display the given data. * * @param title The page id, used for the title of the chart. * @param data the data to plot./*from www. j a v a 2s .c om*/ */ public MinMeanMaxChart(final String title, final SortedSet<Measurement> data) { // The renderer that does all the real work here: final MinMaxCategoryRenderer minMaxRenderer = new MinMaxCategoryRenderer(); minMaxRenderer.setObjectIcon(new FilledCircle()); // Munge the data into form JFreeChart can use: DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Measurement m : data) { // This ordering gives max=red, min=green, mean=blue dataset.addValue(m.getMaximumTime(), "max", m.getBuildId().getBuildName()); dataset.addValue(m.getAverageTime(), "mean", m.getBuildId().getBuildName()); dataset.addValue(m.getMinimumTime(), "min", m.getBuildId().getBuildName()); } // Create the plot area: final CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset); plot.setRenderer(minMaxRenderer); plot.setDomainAxis(new CategoryAxis("Build")); // TO DO: i18n plot.setRangeAxis(new NumberAxis("RT")); // Build labels running diagonally under the bars of the chart. plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(false); // the legend here would be the "min", "max", "mean" strings used when created int category data set. boolean showLegend = true; // Render the chart: JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); chart.setTitle(title); chart.setBackgroundPaint(Color.WHITE); chart.setBorderVisible(false); if (showLegend) { chart.getLegend().setBorder(BlockBorder.NONE); } this.setChart(chart); }
From source file:peakmlviewer.dialog.peakinformation.Graph.java
public Graph(Composite parent) { super(parent, SWT.EMBEDDED); setLayout(new FillLayout()); // create the chart linechart = ChartFactory.createLineChart(null, "", "Abundance", dataset_intensity, PlotOrientation.VERTICAL, false, // legend false, // tooltips false // urls );/*from w w w.ja v a2 s. co m*/ CategoryPlot plot = (CategoryPlot) linechart.getPlot(); // make the labels for the xaxis 45 degrees CategoryAxis xaxis = (CategoryAxis) plot.getDomainAxis(); xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // add the mass accuracy yaxis NumberAxis yaxis_massacc = new NumberAxis("Mass accuracy (ppm)"); plot.setRangeAxis(1, yaxis_massacc); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // create the mass accuracy dataset dataset_ppm = new DefaultCategoryDataset(); plot.setDataset(1, dataset_ppm); plot.mapDatasetToRangeAxis(1, 1); // create the renderer for the mass accuracy dataset LineAndShapeRenderer renderer_ppm = new LineAndShapeRenderer(); renderer_ppm.setBaseShapesFilled(true); renderer_ppm.setBaseShapesVisible(true); renderer_ppm.setBaseStroke( new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { 5, 5 }, 0)); plot.setRenderer(1, renderer_ppm); // setup the renderer for the intensity dataset LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(true); // general properties linechart.setBackgroundPaint(Color.WHITE); linechart.setBorderVisible(false); linechart.setAntiAlias(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); // add the components // -------------------------------------------------------------------------------- // This uses the SWT-trick for embedding awt-controls in an SWT-Composit. try { System.setProperty("sun.awt.noerasebackground", "true"); } catch (NoSuchMethodError error) { ; } java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this); // create a new ChartPanel, without the popup-menu (5x false) frame.add(new ChartPanel(linechart, false, false, false, false, false)); // -------------------------------------------------------------------------------- }