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:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java
/** * Updates the display. This method must only be invoked on the event * dispatch thread.// w w w. jav a 2 s . c om */ protected void update() { XYSeriesCollection dataset = new XYSeriesCollection(); //generate approximation set for (int seedIndex : seedList.getSelectedIndices()) { Accumulator accumulator = accumulators.get(seedIndex); int index = 0; if (!accumulator.keySet().contains("Approximation Set")) { continue; } while ((index < accumulator.size("NFE") - 1) && ((Integer) accumulator.get("NFE", index) < slider.getValue())) { index++; } List<?> list = (List<?>) accumulator.get("Approximation Set", index); XYSeries series = new XYSeries(localization.getString("text.seed", seedIndex + 1), false, true); for (Object object : list) { Solution solution = (Solution) object; series.add(getValue(solution, 0), getValue(solution, 1)); } dataset.addSeries(series); } //generate reference set if (referenceSet != null) { XYSeries series = new XYSeries(localization.getString("text.referenceSet"), false, true); for (Solution solution : referenceSet) { series.add(getValue(solution, 0), getValue(solution, 1)); } dataset.addSeries(series); } JFreeChart chart = ChartFactory.createScatterPlot(getTitle() + " @ " + slider.getValue() + " NFE", (String) xAxisSelection.getSelectedItem(), (String) yAxisSelection.getSelectedItem(), dataset, PlotOrientation.VERTICAL, true, true, false); //set the renderer to only display shapes XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); for (int i = 0; i < dataset.getSeriesCount(); i++) { Paint paint = paintHelper.get(dataset.getSeriesKey(i)); renderer.setSeriesPaint(i, paint); } plot.setRenderer(renderer); //set the zoom based on the user's preferences if ((initialRangeBounds == null) || (initialDomainBounds == null)) { initialRangeBounds = plot.getRangeAxis().getRange(); initialDomainBounds = plot.getDomainAxis().getRange(); } if (useInitialBounds.isSelected()) { plot.getRangeAxis().setRange(initialRangeBounds); plot.getDomainAxis().setRange(initialDomainBounds); } else if (useZoomBounds.isSelected()) { if ((zoomRangeBounds == null) || (zoomDomainBounds == null)) { zoomRangeBounds = initialRangeBounds; zoomDomainBounds = initialDomainBounds; } plot.getRangeAxis().setRange(zoomRangeBounds); plot.getDomainAxis().setRange(zoomDomainBounds); } else if (useReferenceSetBounds.isSelected()) { if (referenceRangeBounds.getLength() > 0.0) { plot.getRangeAxis().setRange(referenceRangeBounds); } if (referenceDomainBounds.getLength() > 0.0) { plot.getDomainAxis().setRange(referenceDomainBounds); } } //register with the chart to receive zoom events chart.addChangeListener(this); chartContainer.removeAll(); chartContainer.add(new ChartPanel(chart), BorderLayout.CENTER); chartContainer.revalidate(); chartContainer.repaint(); }
From source file:MSUmpire.LCMSPeakStructure.LCMSPeakMS1.java
public void GenerateMassCalibrationRTMap() throws IOException { String pngfile = FilenameUtils.getFullPath(ScanCollectionName) + "/" + FilenameUtils.getBaseName(ScanCollectionName) + "_masscaliRT.png"; XYSeries series = new XYSeries("PSM"); XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); LoessInterpolator loessInterpolator = new LoessInterpolator(0.75, //bandwidth, 2//robustnessIters );/*from w w w . ja va 2 s . c om*/ for (PSM psm : this.IDsummary.PSMList.values()) { float ppm = InstrumentParameter.CalcSignedPPM(psm.ObserPrecursorMass, psm.NeutralPepMass); series.add(new XYDataItem(psm.RetentionTime, ppm)); } double x[] = new double[IDsummary.PSMList.size()]; double y[] = new double[x.length]; double currentmin = 0f; for (int i = 0; i < series.getItemCount(); i++) { x[i] = (double) series.getX(i); if (x[i] <= currentmin) { x[i] = currentmin + 0.0001f; } currentmin = x[i]; y[i] = (double) series.getY(i); } Masscalibrationfunction = loessInterpolator.interpolate(x, y); XYSeries smoothline = new XYSeries("Loess Regression"); double xvalue = x[0]; while (xvalue < x[x.length - 1]) { smoothline.add(xvalue, Masscalibrationfunction.value(xvalue)); xvalue += 0.05d; } xySeriesCollection.addSeries(smoothline); xySeriesCollection.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot("Mass calibration", "RT", "Mass error (ppm)", xySeriesCollection, PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(1, Color.blue); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3)); renderer.setSeriesStroke(1, new BasicStroke(1.0f)); xyPlot.setBackgroundPaint(Color.white); ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600); }
From source file:charts.Chart.java
public static void PontosXY() { XYSeries series2 = new XYSeries("Max Value"); series2.add(30.0, 15.0);//from w w w . j ava 2 s .c om series2.add(20.0, 30.0); series2.add(10.0, 75.0); series2.add(40.0, 23.0); series2.add(5.0, 50.0); series2.add(25.0, 45.0); XYSeries series3 = new XYSeries("Min Value"); series3.add(10.0, 15.0); XYSeriesCollection series = new XYSeriesCollection(); series.addSeries(series2); series.addSeries(series3); JFreeChart jfreechart = ChartFactory.createScatterPlot("Sample XY Chart", // Title "Height", // X-Axis label "Weight", // Y-Axis label series, // Dataset PlotOrientation.VERTICAL, true, // Show legend false, false); JFrame janela = new JFrame("Example of the XY series graphic"); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); janela.setContentPane(jpanel); janela.pack(); RefineryUtilities.centerFrameOnScreen(janela); janela.setVisible(true); }
From source file:org.gwaspi.reports.GenericReportGenerator.java
public static XYPlot buildQQPlot(OperationKey testOpKey, int df) throws IOException { if (df != 1 && df != 2) { throw new IllegalArgumentException("Only df = 1 or 2 is supported; it is " + df); }// w w w.ja v a 2 s . c o m //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS"> final Config config = Config.getSingleton(); final Color background = config.getColor(PLOT_QQ_BACKGROUND_CONFIG, PLOT_QQ_BACKGROUND_DEFAULT); final Color actual = config.getColor(PLOT_QQ_ACTUAL_CONFIG, PLOT_QQ_ACTUAL_DEFAULT); final Color sigma = config.getColor(PLOT_QQ_SIGMA_CONFIG, PLOT_QQ_SIGMA_DEFAULT); final Color mu = config.getColor(PLOT_QQ_MU_CONFIG, PLOT_QQ_MU_DEFAULT); //</editor-fold> //<editor-fold defaultstate="expanded" desc="GET X^2"> List<Double> obsChiSqrVals = assembleQQPlotData(testOpKey); int N = obsChiSqrVals.size(); List<Double> expChiSqrDist; if (df == 1) { expChiSqrDist = Chisquare.getChiSquareDistributionDf1(N, 1.0f); } else { // df == 2 expChiSqrDist = Chisquare.getChiSquareDistributionDf2(N, 1.0f); } Collections.sort(expChiSqrDist); //</editor-fold> //<editor-fold defaultstate="expanded" desc="GET CONFIDENCE BOUNDARY"> InputStream boundaryStream = GenericReportGenerator.class .getResourceAsStream("/samples/chisqrboundary-df" + df + ".txt"); InputStreamReader isr = new InputStreamReader(boundaryStream); BufferedReader inputBufferReader = new BufferedReader(isr); Double stopValue = expChiSqrDist.get(N - 1); Double currentValue = 0d; List<Double[]> boundary = new ArrayList<Double[]>(); while (currentValue <= stopValue) { String l = inputBufferReader.readLine(); if (l == null) { break; } String[] cVals = l.split(","); Double[] slice = new Double[3]; slice[0] = Double.parseDouble(cVals[0]); slice[1] = Double.parseDouble(cVals[1]); slice[2] = Double.parseDouble(cVals[2]); currentValue = slice[1]; boundary.add(slice); } inputBufferReader.close(); //</editor-fold> XYSeriesCollection dataSeries = new XYSeriesCollection(); XYSeries seriesData = new XYSeries("X"); XYSeries seriesRef = new XYSeries("Expected"); for (int i = 0; i < obsChiSqrVals.size(); i++) { double obsVal = obsChiSqrVals.get(i); double expVal = expChiSqrDist.get(i); seriesData.add(expVal, obsVal); seriesRef.add(expVal, expVal); } //constant chi-square boundaries XYSeries seriesLower = new XYSeries("2 boundary"); XYSeries seriesUpper = new XYSeries(""); for (Double[] slice : boundary) { seriesUpper.add(slice[1], slice[0]); seriesLower.add(slice[1], slice[2]); } dataSeries.addSeries(seriesData); dataSeries.addSeries(seriesRef); dataSeries.addSeries(seriesUpper); dataSeries.addSeries(seriesLower); final XYDataset data = dataSeries; //create QQ plot final boolean withLegend = true; JFreeChart chart = ChartFactory.createScatterPlot("QQ-plot", "Exp X", "Obs X", data, PlotOrientation.VERTICAL, withLegend, false, false); final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setSeriesPaint(0, actual); renderer.setSeriesPaint(1, mu); renderer.setSeriesPaint(2, sigma); renderer.setSeriesPaint(3, sigma); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(2, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(3, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); plot.setRenderer(renderer); // PLOT BACKGROUND COLOR plot.setBackgroundPaint(background); // Hue, saturation, brightness return plot; }
From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java
private JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio", "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); // CHART BACKGROUD COLOR chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9 // GRIDLINES/*from w w w.j ava2s.co m*/ plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f)); plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7 plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9 plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7 plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8 plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); // DOTS RENDERER XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS); // renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); // renderer.setUseOutlinePaint(true); // Set dot shape of the currently appended Series renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2)); renderer.setSeriesVisibleInLegend(0, false); // AXIS double maxHetzy = 0.005; for (int i = 0; i < dataset.getItemCount(0); i++) { if (maxHetzy < dataset.getXValue(0, i)) { maxHetzy = dataset.getXValue(0, i); } } NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis(); hetzyAxis.setAutoRangeIncludesZero(true); hetzyAxis.setAxisLineVisible(true); hetzyAxis.setTickLabelsVisible(true); hetzyAxis.setTickMarksVisible(true); hetzyAxis.setRange(0, maxHetzy * 1.1); double maxMissrat = 0.005; for (int i = 0; i < dataset.getItemCount(0); i++) { if (maxMissrat < dataset.getYValue(0, i)) { maxMissrat = dataset.getYValue(0, i); } } NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis(); missratAxis.setAutoRangeIncludesZero(true); missratAxis.setAxisLineVisible(true); missratAxis.setTickLabelsVisible(true); missratAxis.setTickMarksVisible(true); missratAxis.setRange(0, maxMissrat * 1.1); // Add significance Threshold to subplot final Marker missingThresholdLine = new ValueMarker(missingThreshold); missingThresholdLine.setPaint(Color.blue); final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold); hetzyThresholdLine.setPaint(Color.blue); // Add legend to hetzyThreshold hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold); missingThresholdLine.setLabel("missing. threshold = " + missingThreshold); hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT); hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT); missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO // Marker label if below hetzyThreshold XYItemRenderer lblRenderer = plot.getRenderer(); // THRESHOLD AND SELECTED LABEL GENERATOR MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold); lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator); lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10)); lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI)); // TOOLTIP GENERATOR MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(); lblRenderer.setBaseToolTipGenerator(tooltipGenerator); lblRenderer.setSeriesItemLabelsVisible(0, true); return chart; }
From source file:org.gephi.statistics.plugin.Renumbering.java
public String getReport() { //distribution of values Map<Double, Integer> dist = new HashMap<Double, Integer>(); for (int i = 0; i < N; i++) { Double d = nodeClustering[i]; if (dist.containsKey(d)) { Integer v = dist.get(d); dist.put(d, v + 1);/*from w w w . j ava 2 s. co m*/ } else { dist.put(d, 1); } } //Distribution series XYSeries dSeries = ChartUtils.createXYSeries(dist, "Clustering Coefficient"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dSeries); JFreeChart chart = ChartFactory.createScatterPlot("Clustering Coefficient Distribution", "Value", "Count", dataset, PlotOrientation.VERTICAL, true, false, false); chart.removeLegend(); ChartUtils.decorateChart(chart); ChartUtils.scaleChart(chart, dSeries, false); String imageFile = ChartUtils.renderChart(chart, "clustering-coefficient.png"); NumberFormat f = new DecimalFormat("#0.000"); if (isDirected) { return "<HTML> <BODY> <h1> Clustering Coefficient Metric Report </h1> " + "<hr>" + "<br />" + "<h2> Parameters: </h2>" + "Network Interpretation: " + (isDirected ? "directed" : "undirected") + "<br />" + "<br>" + "<h2> Results: </h2>" + "Average Clustering Coefficient: " + f.format(avgClusteringCoeff) + "<br />" + "The Average Clustering Coefficient is the mean value of individual coefficients.<br /><br />" + imageFile + "<br /><br />" + "<h2> Algorithm: </h2>" + "Simple and slow brute force.<br />" + "</BODY> </HTML>"; } else { return "<HTML> <BODY> <h1> Clustering Coefficient Metric Report </h1> " + "<hr>" + "<br />" + "<h2> Parameters: </h2>" + "Network Interpretation: " + (isDirected ? "directed" : "undirected") + "<br />" + "<br>" + "<h2> Results: </h2>" + "Average Clustering Coefficient: " + f.format(avgClusteringCoeff) + "<br />" + "Total triangles: " + totalTriangles + "<br />" + "The Average Clustering Coefficient is the mean value of individual coefficients.<br /><br />" + imageFile + "<br /><br />" + "<h2> Algorithm: </h2>" + "Matthieu Latapy, <i>Main-memory Triangle Computations for Very Large (Sparse (Power-Law)) Graphs</i>, in Theoretical Computer Science (TCS) 407 (1-3), pages 458-473, 2008<br />" + "</BODY> </HTML>"; } }
From source file:org.bhavaya.ui.view.ChartView.java
private JFreeChart createScatterChart() { JFreeChart chart;//www . jav a2 s.c om GroupedXYDataSet dataset = new GroupedXYDataSet(beanCollection); HashSet allLocators = new HashSet(); allLocators.addAll(configuration.getDomainAxisLocators()); allLocators.addAll(configuration.getRangeAxisLocators()); dataset.setColumnLocators(allLocators); chart = ChartFactory.createScatterPlot("", getDomainName(), getRangeName(), dataset, PlotOrientation.VERTICAL, true, true, false); Plot plot = chart.getPlot(); if (plot instanceof XYPlot && dataset.isXAxisDateAxis()) { ValueAxis axis = ((XYPlot) plot).getDomainAxis(); DateAxis dateAxis = new DateAxis(axis.getLabel()); /*dateAxis.setAutoRange(true); dateAxis.setAutoTickUnitSelection(true);*/ //dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy")); ((XYPlot) plot).setDomainAxis(dateAxis); } return chart; }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java
/** * Creates a scatter plot that visualizes the given data collection. * //w w w. ja v a2 s .c o m * @param aCollection * Data to be visualized. * @param aGeneral * General visual settings to be applied. * @param aAxes * Axis-related visual settings to be applied. * @param aGrid * Grid-related visual settings to be applied. * @param aScatter * Point-related visual settings to be applied. * @return Newly created chart control. */ private static JFreeChart createScatter(XYSeriesCollection aCollection, GeneralVisSettings aGeneral, AxesSettings aAxes, GridSettings aGrid, ScatterSettings aScatter) { JFreeChart chart = ChartFactory.createScatterPlot(null, // title convertLabel(aAxes.getDomainAxisLabel()), // label of X axis convertLabel(aAxes.getRangeAxisLabel()), // label of Y axis aCollection, // dataset PlotOrientation.VERTICAL, // orientation false, // create legend true, // display tooltips false); // generate urls XYPlot plot = chart.getXYPlot(); Range domainDataRange = aAxes.getLogarithmicDomainAxis() ? new Range(logLowerBound(plot.getDataset(), true), plot.getDataRange(plot.getDomainAxis()).getUpperBound()) : plot.getDataRange(plot.getDomainAxis()); Range rangeDataRange = aAxes.getLogarithmicRangeAxis() ? new Range(logLowerBound(plot.getDataset(), false), plot.getDataRange(plot.getRangeAxis()).getUpperBound()) : plot.getDataRange(plot.getRangeAxis()); updateGeneral(plot, aGeneral); updateAxes(plot, aAxes, aGrid, domainDataRange, rangeDataRange); updateScatter(plot, aScatter); chart.setBackgroundPaint(null); return chart; }
From source file:com.rapidminer.gui.plotter.charts.Abstract2DChartPlotter.java
@Override public void updatePlotter() { prepareData();/*from ww w . ja v a 2s.c o m*/ JFreeChart chart; if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0) { if (nominal) { int size = dataSet.getSeriesCount(); chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation colorColumn >= 0 && size < 100 ? true : false, // include legend true, // tooltips false // URLs ); // renderer settings try { chart.getXYPlot().setRenderer(getItemRenderer(nominal, size, this.minColor, this.maxColor)); } catch (Exception e) { // do nothing } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); LabelBlock title = new LabelBlock(getDataTable().getColumnName(colorColumn), new Font("SansSerif", Font.BOLD, 12)); title.setPadding(0, 5, 5, 5); wrapper.add(title, RectangleEdge.LEFT); BlockContainer items = legend.getItemContainer(); wrapper.add(items, RectangleEdge.RIGHT); legend.setWrapper(wrapper); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); // renderer settings try { chart.getXYPlot().setRenderer(getItemRenderer(nominal, -1, minColor, maxColor)); } catch (Exception e) { // do nothing } LegendTitle legendTitle = new LegendTitle(chart.getXYPlot().getRenderer()) { private static final long serialVersionUID = 1288380309936848376L; @Override public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params) { if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn) || dataTable.isDateTime(colorColumn)) { drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7), dataTable, colorColumn, minColor, maxColor); return new BlockResult(); } else { final String minColorString = Tools.formatNumber(minColor); final String maxColorString = Tools.formatNumber(maxColor); drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 75), (int) (area.getCenterY() + 7), getDataTable().getColumnName(colorColumn), minColorString, maxColorString); return new BlockResult(); } } @Override public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) { draw(g2, area, null); } }; BlockContainer wrapper = new BlockContainer(new BorderArrangement()); LabelBlock title = new LabelBlock(getDataTable().getColumnName(colorColumn), new Font("SansSerif", Font.BOLD, 12)); title.setPadding(0, 5, 5, 5); wrapper.add(title, RectangleEdge.LEFT); BlockContainer items = legendTitle.getItemContainer(); wrapper.add(items, RectangleEdge.RIGHT); legendTitle.setWrapper(wrapper); chart.addLegend(legendTitle); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); } // GENERAL CHART SETTINGS // set the background colors for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(false); // general plot settings XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (axis[X_AXIS] >= 0) { if (dataTable.isNominal(axis[X_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[X_AXIS], i); } plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values)); } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { if (logScales[X_AXIS]) { LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setDomainAxis(domainAxis); } else { NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setAutoRangeStickyZero(false); domainAxis.setAutoRangeIncludesZero(false); plot.setDomainAxis(domainAxis); } } } if (axis[X_AXIS] >= 0) { Range range = getRangeForDimension(axis[X_AXIS]); if (range != null) { plot.getDomainAxis().setRange(range, true, false); } else { plot.getDomainAxis().setAutoRange(true); } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } // range axis if (axis[Y_AXIS] >= 0) { if (dataTable.isNominal(axis[Y_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[Y_AXIS], i); } plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values)); } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) { DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setRangeAxis(rangeAxis); } else { if (logScales[Y_AXIS]) { LogAxis rangeAxis = new LogAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setRangeAxis(rangeAxis); } else { NumberAxis rangeAxis = new NumberAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setAutoRangeStickyZero(false); rangeAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(rangeAxis); } } } plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); if (axis[Y_AXIS] >= 0) { Range range = getRangeForDimension(axis[Y_AXIS]); if (range != null) { plot.getRangeAxis().setRange(range, true, false); } else { plot.getRangeAxis().setAutoRange(true); } } // Chart Panel Settings AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); // react to mouse clicks panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { if (e.getTrigger().getClickCount() > 1) { if (e.getEntity() instanceof XYItemEntity) { XYItemEntity entity = (XYItemEntity) e.getEntity(); if (entity != null) { String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem())); if (id != null) { ObjectVisualizer visualizer = ObjectVisualizerService .getVisualizerForObject(dataTable); visualizer.startVisualization(id); } } } } } @Override public void chartMouseMoved(ChartMouseEvent e) { } }); } else { panel.setChart(chart); } // tooltips class CustomXYToolTipGenerator implements XYToolTipGenerator { public CustomXYToolTipGenerator() { } private String formatValue(int axis, double value) { if (dataTable.isNominal(axis)) { // TODO add mapping of value to nominal value return Tools.formatIntegerIfPossible(value); } else if (dataTable.isNumerical(axis)) { return Tools.formatIntegerIfPossible(value); } else if (dataTable.isDate(axis)) { return Tools.createDateAndFormat(value); } else if (dataTable.isTime(axis)) { return Tools.createTimeAndFormat(value); } else if (dataTable.isDateTime(axis)) { return Tools.createDateTimeAndFormat(value); } return "?"; } @Override public String generateToolTip(XYDataset dataset, int row, int column) { String id = idMap.get(new SeriesAndItem(row, column)); if (id != null) { return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", " + formatValue(axis[X_AXIS], dataset.getXValue(row, column)) + ", " + formatValue(axis[Y_AXIS], dataset.getYValue(row, column)) + ")</html>"; } else { return "<html>(" + dataset.getSeriesKey(row) + ", " + formatValue(axis[X_AXIS], dataset.getXValue(row, column)) + ", " + formatValue(axis[Y_AXIS], dataset.getYValue(row, column)) + ")</html>"; } } } for (int i = 0; i < dataSet.getSeriesCount(); i++) { plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator()); } }
From source file:ca.nengo.plot.impl.DefaultPlotter.java
/** * @see ca.nengo.plot.Plotter#doPlot(ca.nengo.util.SpikePattern) *///w w w . ja va 2 s. c o m public void doPlot(SpikePattern pattern) { XYSeriesCollection dataset = getDataset(pattern); JFreeChart chart = ChartFactory.createScatterPlot("Spike Raster", "Time (s)", "Neuron #", dataset, PlotOrientation.VERTICAL, false, false, false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); configSpikeRenderer(renderer); showChart(chart, "Spike Raster"); }