List of usage examples for org.jfree.chart.plot XYPlot setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:edu.ucsf.valelab.spotintensityanalysis.plot.PlotUtils.java
/** * Create a frame with a plot of the data given in XYSeries overwrite any * previously created frame with the same title * /*w w w.j a v a 2 s.c o m*/ * @param title shown in the top of the plot * @param data array with data series to be plotted * @param xTitle Title of the X axis * @param yTitle Title of the Y axis * @param showShapes whether or not to draw shapes at the data points * @param annotation to be shown in plot * @return Frame that displays the data */ public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes, String annotation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); // calculate min and max to scale the graph double minX, minY, maxX, maxY; minX = data[0].getMinX(); minY = data[0].getMinY(); maxX = data[0].getMaxX(); maxY = data[0].getMaxY(); for (XYSeries d : data) { dataset.addSeries(d); if (d.getMinX() < minX) { minX = d.getMinX(); } if (d.getMaxX() > maxX) { maxX = d.getMaxX(); } if (d.getMinY() < minY) { minY = d.getMinY(); } if (d.getMaxY() > maxY) { maxY = d.getMaxY(); } } JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); for (int i = 0; i < data.length; i++) { renderer.setSeriesFillPaint(i, Color.white); renderer.setSeriesLinesVisible(i, true); } renderer.setSeriesPaint(0, Color.blue); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); if (data.length > 1) { renderer.setSeriesPaint(1, Color.red); Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(1, square, false); } if (data.length > 2) { renderer.setSeriesPaint(2, Color.darkGray); Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f); renderer.setSeriesShape(2, rect, false); } if (data.length > 3) { renderer.setSeriesPaint(3, Color.magenta); Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f); renderer.setSeriesShape(3, rect, false); } for (int i = 0; i < data.length; i++) { if (showShapes.length > i && !showShapes[i]) { renderer.setSeriesShapesVisible(i, false); } } // place annotation at 80 % of max X, maxY XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY); plot.addAnnotation(an); renderer.setUseFillPaint(true); if (graphFrame_ == null) graphFrame_ = new MyChartFrame(title, chart); else graphFrame_.getChartPanel().setChart(chart); graphFrame_.getChartPanel().setMouseWheelEnabled(true); graphFrame_.pack(); final MyChartFrame privateFrame = graphFrame_; graphFrame_.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { privateFrame.dispose(); } }); graphFrame_.setVisible(true); return graphFrame_; }
From source file:utilities.GraphViewer.java
private ChartPanel graphe() { JFreeChart graph = ChartFactory.createXYLineChart("Sensors Energy", "Time", "Energy", dataset, PlotOrientation.VERTICAL, true, true, false); ChartPanel cPanel = new ChartPanel(graph); cPanel.setBackground(Color.blue); cPanel.setPreferredSize(new Dimension(800, 600)); XYPlot plot = graph.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); return cPanel; }
From source file:com.itemanalysis.jmetrik.graph.scatterplot.ScatterplotPanel.java
public void setGraph() { DefaultXYDataset dataset = new DefaultXYDataset(); PlotOrientation orientation = PlotOrientation.VERTICAL; try {//from w ww . j a v a 2 s . c om chart = ChartFactory.createScatterPlot(title, // chart title xlabel, // x axis label ylabel, // y axis label dataset, // data orientation, showLegend, // include legend true, // tooltips false // urls ); if (subtitle != null && !"".equals(subtitle)) { TextTitle subtitle1 = new TextTitle(subtitle); chart.addSubtitle(subtitle1); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }
From source file:kardex.graficakardex.java
public graficakardex() { datosxy.removeAllSeries();// w w w .j av a 2s. co m //sxy.add(x[0], y[0]); y = new double[kardex.valor.length]; y = kardex.valor; int n = y.length; for (int i = 0; i < n; i++) { sxy.add(i, y[i]); // System.out.print(x[i]+"-"+i+" "); } datosxy.addSeries(sxy); graficaxy = ChartFactory.createXYLineChart("Grafica de Stock de Producto", "transacciones", "cantidades", datosxy, PlotOrientation.VERTICAL, true, true, true); graficaxy.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) graficaxy.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); configurarDomainAxis(domainAxis); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } }
From source file:net.sf.smbt.ui.btc.views.AbstractBlockchainView.java
public void addCharts(Composite folder) { chart = ChartFactory.createXYStepChart(getChartTitle(), getXAxisLabel(), getYAxisLabel(), null, PlotOrientation.VERTICAL, true, // legend true, // tooltips false // urls );//from ww w . j av a2 s . com // then customise it a little... final XYPlot plot = chart.getXYPlot(); chart.getTitle().setPaint(Color.LIGHT_GRAY); chart.setBackgroundPaint(new java.awt.Color(66, 66, 66)); plot.setBackgroundPaint(new java.awt.Color(66, 66, 66)); plot.getRenderer().setSeriesVisibleInLegend(false); plot.getRangeAxis().setTickLabelPaint(Color.LIGHT_GRAY); plot.getRangeAxis().setLabelPaint(Color.LIGHT_GRAY); plot.getDomainAxis().setTickLabelPaint(Color.LIGHT_GRAY); plot.getDomainAxis().setLabelPaint(Color.LIGHT_GRAY); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); // and present it in a frame... new ChartComposite(folder, SWT.NONE, chart, true); }
From source file:web.diva.server.unused.PCAGenerator.java
public PCAImageResult generateChart(String path, PCAResults pcaResults, int[] subSelectionData, int[] selection, boolean zoom, boolean selectAll, String imgName, double w, double h, DivaDataset divaDataset) { XYDataset dataset = this.createDataset(pcaResults.getPoints(), subSelectionData, selection, zoom, divaDataset);//from w w w . j a va 2 s .co m final JFreeChart chart = ChartFactory.createScatterPlot("", // chart title "Principal Component" + (pcaResults.getPcai() + 1), // x axis label "Principal Component " + (pcaResults.getPcaii() + 1), // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotHeight(5); renderer.setDotWidth(5); if (selectAll) { int i = 0; for (String col : seriesList.keySet()) { if (col.equalsIgnoreCase("unGrouped")) { col = "#000000"; } renderer.setSeriesPaint(i, imgGenerator.hex2Rgb(col)); i++; } } else if (selection == null) { renderer.setPaint(Color.LIGHT_GRAY); int i = 0; for (String col : seriesList.keySet()) { if (col.equalsIgnoreCase("unGrouped")) { col = "#000000"; } renderer.setSeriesPaint(i, imgGenerator.hex2Rgb(col)); i++; } } else { int i = 0; for (String col : seriesList.keySet()) { if (col.equalsIgnoreCase("unGrouped")) { renderer.setSeriesPaint(i, Color.LIGHT_GRAY); } else { renderer.setSeriesPaint(i, imgGenerator.hex2Rgb(col)); } i++; } } plot.setRenderer(renderer); plot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); NumberAxis xAxis = new NumberAxis("Principal Component" + (pcaResults.getPcai() + 1)); xAxis.setVerticalTickLabels(true); boolean auto = xAxis.getAutoRangeIncludesZero(); xAxis.setAutoRangeIncludesZero(true ^ auto); NumberAxis yAxis = new NumberAxis("Principal Component" + (pcaResults.getPcaii() + 1)); yAxis.setAutoRangeIncludesZero(true ^ auto); yAxis.setTickUnit(new NumberTickUnit(1)); plot.setDomainAxis(0, xAxis); plot.setRangeAxis(0, yAxis); double MaxX = xAxis.getRange().getUpperBound(); double MinX = xAxis.getRange().getLowerBound(); double MaxY = yAxis.getRange().getUpperBound(); double MinY = yAxis.getRange().getLowerBound(); chartRenderingInfo.clear(); String imgUrl = imgGenerator.saveToFile(chart, w, h, chartRenderingInfo); PCAImageResult imgUtilRes = new PCAImageResult(); imgUtilRes.setImgString(imgUrl); imgUtilRes.setDataAreaMaxX(chartRenderingInfo.getPlotInfo().getDataArea().getMaxX()); imgUtilRes.setDataAreaMaxY(chartRenderingInfo.getPlotInfo().getDataArea().getMaxY()); imgUtilRes.setDataAreaMinY(chartRenderingInfo.getPlotInfo().getDataArea().getMinY()); imgUtilRes.setDataAreaMinX(chartRenderingInfo.getPlotInfo().getDataArea().getMinX()); imgUtilRes.setMaxX(MaxX); imgUtilRes.setMaxY(MaxY); imgUtilRes.setMinX(MinX); imgUtilRes.setMinY(MinY); return imgUtilRes; }
From source file:entrenamiento.grafica.java
public grafica() { XYSeries sxy = new XYSeries("pesos"); datosxy.removeAllSeries();// www. j a va2s . co m //sxy.add(x[0], y[0]); y = new double[Entrenamiento.valor.length]; y = Entrenamiento.valor; int n = y.length; for (int i = 0; i < n; i++) { sxy.add(i, y[i]); // System.out.print(x[i]+"-"+i+" "); } datosxy.addSeries(sxy); graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy, PlotOrientation.VERTICAL, true, true, true); graficaxy.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) graficaxy.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); configurarDomainAxis(domainAxis); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } }
From source file:entrenamiento.grafica2.java
public grafica2() { XYSeries sxy = new XYSeries("pesos"); datosxy.removeAllSeries();//from ww w .j a v a2 s .c om //sxy.add(x[0], y[0]); y = new double[Entrenamiento2.valor.length]; y = Entrenamiento2.valor; int n = y.length; for (int i = 0; i < n; i++) { sxy.add(i, y[i]); // System.out.print(x[i]+"-"+i+" "); } datosxy.addSeries(sxy); graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy, PlotOrientation.VERTICAL, true, true, true); graficaxy.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) graficaxy.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); configurarDomainAxis(domainAxis); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } }
From source file:PlotsBuilding.PlotPanel.java
private JFreeChart createChart(XYDataset xyDataset, ArrayList<Integer> seriesCount, double y1, double y2) { NumberAxis domainAxis = new NumberAxis("x"); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setPositiveArrowVisible(true); NumberAxis rangeAxis = new NumberAxis("y"); rangeAxis.setRange(y1, y2);/*from ww w . j a v a 2s . c o m*/ rangeAxis.setPositiveArrowVisible(true); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); int start = 0; int color = 50; for (Object series : seriesCount) { for (int i = start; i < start + (int) series; i++) { Color s = new Color(color); renderer.setSeriesPaint(i, s); renderer.setSeriesVisibleInLegend(i, false); renderer.setSeriesVisibleInLegend(start, true); } start = start + (int) series; color *= 100; } renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(xyDataset, domainAxis, rangeAxis, renderer); PlotOrientation orientation = PlotOrientation.VERTICAL; plot.setOrientation(orientation); plot.setBackgroundPaint(Color.white); chart = new JFreeChart(plot); chart.setBackgroundPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.RIGHT); chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); return chart; }
From source file:CargarEntrenamiento.grafica2.java
public grafica2() { datosxy.removeAllSeries();/*from www . j av a 2s. c o m*/ XYSeries sxy = new XYSeries("pesos"); //sxy.add(x[0], y[0]); y = new double[cargarEntreno.valorentreno.length]; y = cargarEntreno.valorentreno; int n = y.length; for (int i = 0; i < n; i++) { sxy.add(i, y[i]); // System.out.print(x[i]+"-"+i+" "); } datosxy.addSeries(sxy); graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy, PlotOrientation.VERTICAL, true, true, true); graficaxy.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) graficaxy.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); configurarDomainAxis(domainAxis); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } }