List of usage examples for org.jfree.chart ChartFactory createScatterPlot
public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:adept.utilities.Grapher.java
/** * Make time vs size graph.//w w w. j a v a 2s .c o m * * @param timevalues the timevalues * @param sizevalues the sizevalues * @param filename the filename * @param linelabel the linelabel * @param Xlabel the xlabel * @param Ylabel the ylabel * @param title the title */ public static void makeTimeVsSizeGraph(ArrayList<Double> timevalues, ArrayList<Double> sizevalues, File filename, String linelabel, String Xlabel, String Ylabel, String title) { try { XYSeriesCollection scatter_plot_dataset = new XYSeriesCollection(); XYSeries data = new XYSeries(linelabel); for (int i = 0; i < sizevalues.size(); i++) { data.add(sizevalues.get(i), timevalues.get(i)); } scatter_plot_dataset.addSeries(data); /* Step -2:Define the JFreeChart object to create line chart */ JFreeChart scatterPlotObject = ChartFactory.createScatterPlot(Ylabel, Xlabel, title, scatter_plot_dataset, PlotOrientation.VERTICAL, true, true, false); /* Step -3 : Write line chart to a file */ int width = 640; /* Width of the image */ int height = 480; /* Height of the image */ ChartUtilities.saveChartAsPNG(filename, scatterPlotObject, width, height); } catch (Exception e) { e.printStackTrace(); } }
From source file:umontreal.iro.lecuyer.charts.ScatterChart.java
protected void init(String title, String XLabel, String YLabel) { // create the chart... chart = ChartFactory.createScatterPlot(title, // chart title XLabel, // x axis label YLabel, // y axis label dataset.getSeriesCollection(), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from www . j av a 2 s. c o m ((XYPlot) chart.getPlot()).setRenderer(dataset.getRenderer()); // Initialize axis variables initAxis(); int nb = getSeriesCollection().getSeriesCollection().getSeriesCount(); for (int i = 0; i < nb; i++) { getSeriesCollection().setDashPattern(i, "only marks"); getSeriesCollection().setMarksType(i, "+"); } }
From source file:org.ow2.clif.jenkins.chart.CallChart.java
@Override protected JFreeChart createChart() { XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(this.eventSerie); JFreeChart chart;//w w w . ja va 2 s . c o m if (this.scatterPlot) { chart = ChartFactory.createScatterPlot(getBasicTitle(), // chart title Messages.CallChart_Time(), // x axis label Messages.CallChart_ResponseTime(), // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); } else { chart = ChartFactory.createXYLineChart(getBasicTitle(), // chart title Messages.CallChart_Time(), // x axis label this.chartId.getEvent(), // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); } chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); Shape cross = ShapeUtilities.createDiamond(3); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShape(cross); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShape(0, cross); plot.setRenderer(renderer); // Force the 0 on vertical axis NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Force the 0 on horizontal axis NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(true); return chart; }
From source file:org.jfree.chart.demo.ScatterPlotDemo.java
/** * A demonstration application showing a scatter plot. * /*from www . j av a2 s . co m*/ * @param title * the frame title. */ public ScatterPlotDemo(final String title) { super(title); final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final Legend legend = chart.getLegend(); if (legend instanceof StandardLegend) { final StandardLegend sl = (StandardLegend) legend; sl.setDisplaySeriesShapes(true); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.setVerticalZoom(true); chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.ScatterPlotChartExpression.java
protected JFreeChart computeXYChart(final XYDataset xyDataset) { final JFreeChart chart; if (xyDataset instanceof TimeSeriesCollection) { chart = ChartFactory.createTimeSeriesChart(computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, isShowLegend(), false, false); final XYPlot xyPlot = chart.getXYPlot(); final XYLineAndShapeRenderer itemRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(itemRenderer.getBaseToolTipGenerator()); renderer.setURLGenerator(itemRenderer.getURLGenerator()); xyPlot.setRenderer(renderer);//from ww w . jav a 2 s . co m } else { final PlotOrientation orientation = computePlotOrientation(); chart = ChartFactory.createScatterPlot(computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, orientation, isShowLegend(), false, false); } chart.getXYPlot().setRenderer(new XYDotRenderer()); configureLogarithmicAxis(chart.getXYPlot()); return chart; }
From source file:ui.FitnessGraph.java
/** * Creates a chart./*from ww w . j av a 2 s. c o m*/ * * @param dataset * the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createScatterPlot("Fitness v generation", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f, // 1.0f)); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); // renderer.setSeriesStroke(1, new BasicStroke(0.01f)); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.jfree.chart.demo.ScatterPlotDemo4.java
/** * A demonstration application showing a scatter plot. * * @param title the frame title.//from w ww . j a v a 2s.co m */ public ScatterPlotDemo4(final String title) { super(title); final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDotRenderer()); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeScatterPeriodChartData.java
@Override public JFreeChart getJFreeChart() { if (chart == null) { chart = ChartFactory.createScatterPlot(title, xaxis, yaxis, coll, PlotOrientation.VERTICAL, false, false, false);/* www.ja v a 2s. c o m*/ XYDotRenderer render = new XYDotRenderer(); render.setDotHeight(2); render.setDotWidth(2); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(render); } return chart; }
From source file:ChartPanelMaker.java
public static ChartPanel createChart(ArrayList<Voter> voters, ArrayList<Candidate> candidates, ArrayList<Candidate> committee, String title) { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries comitteeDataset = new XYSeries("Committee"); for (Candidate c : committee) { comitteeDataset.add(c.getX(), c.getY()); }// www .ja va 2s. c om dataset.addSeries(comitteeDataset); int n = voters.size(); int m = candidates.size(); int skipN = n / 150; if (skipN < 1) { skipN = 1; } int skipM = m / 150; if (skipM < 1) { skipM = 1; } Collections.sort(voters, Election.VoterNameComparator); Collections.sort(candidates, Election.CandidateNameComparator); XYSeries voterDataset = new XYSeries("Voters"); for (int i = 0; i < n; i++) { Voter v = voters.get(i); if (i % skipN == 0) { voterDataset.add(v.getX(), v.getY()); } } dataset.addSeries(voterDataset); XYSeries candidateDataset = new XYSeries("Candidates"); for (int i = 0; i < m; i++) { Candidate c = candidates.get(i); if (i % skipM == 0) { candidateDataset.add(c.getX(), c.getY()); } } dataset.addSeries(candidateDataset); Shape committeeShape = ShapeUtilities.createDiamond(5); Shape voterShape = ShapeUtilities.createDownTriangle(3); Shape candidateShape = ShapeUtilities.createUpTriangle(3); Color committeeColor = Color.DARK_GRAY; Color voterColor = Color.ORANGE; Color candidateColor = Color.LIGHT_GRAY; JFreeChart chart = ChartFactory.createScatterPlot(title, "", "", dataset, PlotOrientation.VERTICAL, true, true, true); XYPlot plot = chart.getXYPlot(); XYItemRenderer r = plot.getRenderer(); r.setSeriesShape(0, committeeShape); r.setSeriesPaint(0, committeeColor); r.setSeriesShape(1, voterShape); r.setSeriesPaint(1, voterColor); r.setSeriesShape(2, candidateShape); r.setSeriesPaint(2, candidateColor); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
From source file:org.jfree.expdemo.SelectionDemo3.java
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo3", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainPannable(true);/* www .j av a 2 s. c om*/ plot.setRangePannable(true); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); //XYItemRenderer r = plot.getRenderer(); XYDotRenderer r = new XYDotRenderer(); r.setDotHeight(2); r.setDotWidth(2); r.setSeriesPaint(0, Color.blue); r.setSeriesPaint(1, Color.green); r.setSeriesPaint(2, Color.yellow); r.setSeriesPaint(3, Color.orange); plot.setRenderer(r); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(2.0f); domainAxis.setMinorTickCount(2); domainAxis.setMinorTickMarksVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickCount(2); rangeAxis.setMinorTickMarksVisible(true); //add selection specific rendering IRSUtilities.setSelectedItemPaint(r, ext, Color.red); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }