List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setSeriesLinesVisible
public void setSeriesLinesVisible(int series, boolean visible)
From source file:mzmatch.ipeak.align.CowCoda.java
@SuppressWarnings("unchecked") public static void main(String args[]) { final String lbl_mcq = "mcq"; try {/*from w w w. j a va 2s .c o m*/ Tool.init(); // parse the commandline options final Options options = new Options(); CmdLineParser cmdline = new CmdLineParser(options); // check whether we need to show the help cmdline.parse(args); if (options.help) { Tool.printHeader(System.out, application, version); cmdline.printUsage(System.out, ""); return; } if (options.verbose) { Tool.printHeader(System.out, application, version); cmdline.printOptions(); } // check the command-line parameters int filetype = JFreeChartTools.PDF; { if (options.ppm == -1) { System.err.println("[ERROR]: the ppm-value needs to be set."); System.exit(0); } if (options.order == -1) { System.err.println("[ERROR]: the order for the polynomial fit needs to be set."); System.exit(0); } if (options.maxrt == -1) { System.err.println("[ERROR]: the maximum retention time shift is not set."); System.exit(0); } if (options.image != null) { String extension = options.image.substring(options.image.lastIndexOf('.') + 1); if (extension.toLowerCase().equals("png")) filetype = JFreeChartTools.PNG; else if (extension.toLowerCase().equals("pdf")) filetype = JFreeChartTools.PDF; else { System.err.println( "[ERROR]: file extension of the image file needs to be either PDF or PNG."); System.exit(0); } } // if the output directories do not exist, create them if (options.output != null) Tool.createFilePath(options.output, true); if (options.image != null) Tool.createFilePath(options.image, true); if (options.selection != null) Tool.createFilePath(options.selection, true); } // load the data if (options.verbose) System.out.println("Loading the data"); double maxrt = 0; Vector<ParseResult> data = new Vector<ParseResult>(); Vector<IPeakSet<IPeak>> matchdata = new Vector<IPeakSet<IPeak>>(); for (String file : options.input) { System.out.println("- " + new File(file).getName()); // load the mass chromatogram data ParseResult result = PeakMLParser.parse(new FileInputStream(file), true); data.add(result); // select the best mass chromatograms Vector<IPeak> selection = new Vector<IPeak>(); for (IPeak peak : (IPeakSet<IPeak>) result.measurement) { maxrt = Math.max(maxrt, maxRT(peak)); double mcq = codaDW(peak); peak.addAnnotation(lbl_mcq, Double.toString(mcq), Annotation.ValueType.DOUBLE); if (mcq >= options.codadw) selection.add(peak); } // keep track of the selected mass chromatograms int id = options.input.indexOf(file); IPeakSet<IPeak> peakset = new IPeakSet<IPeak>(selection); peakset.setMeasurementID(id); for (IPeak mc : peakset) mc.setMeasurementID(id); matchdata.add(peakset); } // match the selection together if (options.verbose) System.out.println("Matching the data"); Vector<IPeakSet<IPeak>> matches = IPeak.match((Vector) matchdata, options.ppm, new IPeak.MatchCompare<IPeak>() { public double distance(IPeak peak1, IPeak peak2) { double diff = Math.abs(peak1.getRetentionTime() - peak2.getRetentionTime()); if (diff > options.maxrt) return -1; Signal signal1 = new Signal(peak1.getSignal()); signal1.normalize(); Signal signal2 = new Signal(peak2.getSignal()); signal2.normalize(); double offset = bestOffSet(peak1, peak2, options.maxrt); for (int i = 0; i < signal2.getSize(); ++i) signal2.getX()[i] += offset; double correlation = signal2 .pearsonsCorrelation(signal1)[Statistical.PEARSON_CORRELATION]; if (correlation < 0.5) return -1; // the match-function optimizes toward 0 (it's a distance) return 1 - correlation; } }); // filter out all incomplete sets Vector<IPeakSet<IPeak>> valids = new Vector<IPeakSet<IPeak>>(); for (IPeakSet<IPeak> set : matches) { if (set.size() < options.input.size()) continue; valids.add((IPeakSet) set); } // calculate the alignment factors if (options.verbose) System.out.println("Calculating the alignment factors"); double medians[] = new double[valids.size() + 2]; DataFrame.Double dataframe = new DataFrame.Double(valids.size() + 2, options.input.size()); medians[0] = 0; medians[medians.length - 1] = maxrt; for (int i = 0; i < options.input.size(); ++i) { dataframe.set(0, i, 0.1); dataframe.set(dataframe.getNrRows() - 1, i, 0); } for (int matchid = 0; matchid < valids.size(); ++matchid) { IPeakSet<IPeak> match = valids.get(matchid); // find the most central double offsets[][] = new double[match.size()][match.size()]; for (int i = 0; i < match.size(); ++i) for (int j = i + 1; j < match.size(); ++j) { offsets[i][j] = bestOffSet(match.get(i), match.get(j), options.maxrt); offsets[j][i] = -offsets[i][j]; } int besti = 0; double bestabssum = Double.MAX_VALUE; for (int i = 0; i < match.size(); ++i) { double abssum = 0; for (int j = 0; j < match.size(); ++j) abssum += Math.abs(offsets[i][j]); if (abssum < bestabssum) { besti = i; bestabssum = abssum; } } for (int i = 0; i < match.size(); ++i) dataframe.set(matchid + 1, match.get(i).getMeasurementID(), (i == besti ? 0 : offsets[i][besti])); medians[matchid + 1] = match.get(besti).getRetentionTime(); dataframe.setRowName(matchid, Double.toString(match.get(besti).getRetentionTime())); } double minmedian = Statistical.min(medians); double maxmedian = Statistical.max(medians); // calculate for each profile the correction function PolynomialFunction functions[] = new PolynomialFunction[valids.size()]; for (int i = 0; i < options.input.size(); ++i) functions[i] = PolynomialFunction.fit(options.order, medians, dataframe.getCol(i)); // make a nice plot out of the whole thing if (options.verbose) System.out.println("Writing results"); if (options.image != null) { org.jfree.data.xy.XYSeriesCollection dataset = new org.jfree.data.xy.XYSeriesCollection(); JFreeChart linechart = ChartFactory.createXYLineChart(null, "Retention Time (seconds)", "offset", dataset, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); // setup the colorkey Colormap colormap = new Colormap(Colormap.EXCEL); // get the structure behind the graph XYPlot plot = (XYPlot) linechart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // setup the plot area linechart.setBackgroundPaint(java.awt.Color.WHITE); linechart.setBorderVisible(false); linechart.setAntiAlias(true); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); // create the datasets for (int i = 0; i < options.input.size(); ++i) { org.jfree.data.xy.XYSeries series = new org.jfree.data.xy.XYSeries(dataframe.getColName(i)); org.jfree.data.xy.XYSeries function = new org.jfree.data.xy.XYSeries( dataframe.getColName(i) + "-function"); dataset.addSeries(series); dataset.addSeries(function); renderer.setSeriesPaint(dataset.getSeriesCount() - 1, new java.awt.Color(colormap.getColor(i))); renderer.setSeriesPaint(dataset.getSeriesCount() - 2, new java.awt.Color(colormap.getColor(i))); renderer.setSeriesLinesVisible(dataset.getSeriesCount() - 2, false); renderer.setSeriesShapesVisible(dataset.getSeriesCount() - 2, true); // add the data-points for (int j = 0; j < valids.size(); ++j) series.add(medians[j], dataframe.get(j, i)); for (double x = minmedian; x < maxmedian; ++x) function.add(x, functions[i].getY(x)); } dataset.removeAllSeries(); for (int i = 0; i < options.input.size(); ++i) { Function function = functions[i]; org.jfree.data.xy.XYSeries series = new org.jfree.data.xy.XYSeries(dataframe.getColName(i)); dataset.addSeries(series); renderer.setSeriesPaint(i, new java.awt.Color(colormap.getColor(i))); renderer.setSeriesLinesVisible(i, false); renderer.setSeriesShapesVisible(i, true); // add the data-points for (int j = 0; j < valids.size(); ++j) series.add(medians[j], dataframe.get(j, i) - function.getY(medians[j])); } JFreeChartTools.writeAs(filetype, new FileOutputStream(options.image), linechart, 800, 500); } // save the selected if (options.selection != null) { Header header = new Header(); // set the number of peaks to be stored header.setNrPeaks(valids.size()); // create a set for the measurements SetInfo set = new SetInfo("", SetInfo.SET); header.addSetInfo(set); // create the measurement infos for (int i = 0; i < options.input.size(); ++i) { String file = options.input.get(i); // create the measurement info MeasurementInfo measurement = new MeasurementInfo(i, data.get(i).header.getMeasurementInfo(0)); measurement.addFileInfo(new FileInfo(file, file)); header.addMeasurementInfo(measurement); // add the file to the set set.addChild(new SetInfo(file, SetInfo.SET, i)); } // write the data PeakMLWriter.write(header, (Vector) valids, null, new GZIPOutputStream(new FileOutputStream(options.selection)), null); } // correct the values with the found function and save them for (int i = 0; i < options.input.size(); ++i) { Function function = functions[i]; ParseResult result = data.get(i); IPeakSet<MassChromatogram<Peak>> peakset = (IPeakSet<MassChromatogram<Peak>>) result.measurement; for (IPeak peak : peakset) align(peak, function); File filename = new File(options.input.get(i)); String name = filename.getName(); PeakMLWriter.write(result.header, (Vector) peakset.getPeaks(), null, new GZIPOutputStream(new FileOutputStream(options.output + "/" + name)), null); } } catch (Exception e) { Tool.unexpectedError(e, application); } }
From source file:org.jfree.chart.demo.XYLineAndShapeRendererDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 1", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(); xylineandshaperenderer.setSeriesLinesVisible(0, true); xylineandshaperenderer.setSeriesShapesVisible(0, false); xylineandshaperenderer.setSeriesLinesVisible(1, false); xylineandshaperenderer.setSeriesShapesVisible(1, true); xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); xylineandshaperenderer.setDefaultEntityRadius(6); xyplot.setRenderer(xylineandshaperenderer); return jfreechart; }
From source file:com.moczul.jbacktester.Main.java
private static void showChart(XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart("PKO - PEO", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*from w w w . ja v a 2 s . com*/ final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); XYPlot plot = chart.getXYPlot(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesShapesVisible(3, false); renderer.setSeriesShapesVisible(4, false); plot.setRenderer(renderer); JFrame frame = new JFrame(); frame.setContentPane(chartPanel); frame.pack(); frame.setVisible(true); }
From source file:org.gephi.statistics.plugin.ChartUtils.java
public static void decorateChart(JFreeChart chart) { XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 2, 2)); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainGridlinePaint(java.awt.Color.GRAY); plot.setRangeGridlinePaint(java.awt.Color.GRAY); plot.setRenderer(renderer);//from w w w . j a v a 2 s . c o m }
From source file:org.physionet.wfdb.examples.PlotECGQRSDemo2.java
private static JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart("Plot ECG Demo1 ", // chart title "Time (seconds)", // x axis label "mV", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*from w ww .ja va 2 s . c o m*/ XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShapesFilled(1, true); } return chart; }
From source file:umberto.WeightedClusterCoefficient.ChartUtils.java
public static void decorateChart(JFreeChart chart) { XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 3, 3)); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainGridlinePaint(java.awt.Color.GRAY); plot.setRangeGridlinePaint(java.awt.Color.GRAY); plot.setRenderer(renderer);//from www . j a v a 2 s . c om }
From source file:com.bdb.weather.display.WeatherSenseConstants.java
public static void configureGustRenderer(XYLineAndShapeRenderer renderer, int index) { renderer.setSeriesShape(index,/*from www.j a v a2s . com*/ new Rectangle2D.Double(GUST_SHAPE_X, GUST_SHAPE_Y, GUST_SHAPE_WIDTH, GUST_SHAPE_HEIGHT)); renderer.setSeriesLinesVisible(index, false); renderer.setSeriesShapesVisible(index, true); }
From source file:utils.Graficos_old.java
public static JFreeChart GraficoLinhas(List<CarCapContas> pagar, List<CarCapContas> receber, String titulo) { XYSeries series1 = new XYSeries("Pagar"); // CarCapContas contasPagar = new CarCapContas(); for (CarCapContas contasPagar : pagar) { series1.add(contasPagar.getContaValorTotal(), contasPagar.getContaDataEmissao().getMonth()); }//from w ww . j a v a 2 s .c o m XYSeries series2 = new XYSeries("Receber"); for (CarCapContas contasReceber : receber) { series2.add(contasReceber.getContaValorTotal(), contasReceber.getContaDataEmissao().getMonth()); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); JFreeChart chart = ChartFactory.createXYLineChart(titulo, // 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); // 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); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:max.hubbard.Factoring.Graphing.java
private static JFreeChart createChart(final XYDataset dataset, String equation) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart(equation, // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*www .j a v a2 s . c om*/ // 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); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(new Range(-50, 50)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java
/** * Colorized and transforms a given JFreeChart. * /*from w w w .j a va 2 s . c o m*/ * @author Clement HELIOU (clement.heliou@che-software.com). * @param lineChart the given chart. * @param maxAbscissaValue the max abscissa value of the chart. * @param xValues the x axis values list. * @param yValues the y axis values list. * @param xExcludedValues the x axis excluded values. * @param yExcludedValues the y axis excluded values. * @return the transformed chart. * @since August, 2011. */ public static JFreeChart getColorizedChartFromChart(JFreeChart lineChart, double maxAbscissaValue, List<MatrixResult> xValues, List<MatrixResult> yValues, List<MatrixResult> xExcludedValues, List<MatrixResult> yExcludedValues) { LOGGER.debug("getColorizedChartFromChart()."); lineChart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) lineChart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesStroke(2, new BasicStroke(2)); renderer.setSeriesStroke(3, new BasicStroke(2)); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesShapesVisible(3, false); renderer.setSeriesPaint(0, ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); renderer.setSeriesPaint(1, ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); renderer.setSeriesPaint(2, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); renderer.setSeriesPaint(3, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.setRenderer(renderer); XYTextAnnotation low = new XYTextAnnotation( LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_LOW_NAME), (0.5 * maxAbscissaValue) - 1, maxAbscissaValue + 1), medium = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_MEDIUM_NAME), (1.5 * maxAbscissaValue) - 2, maxAbscissaValue + 1), high = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_HIGH_NAME), 1.5 * maxAbscissaValue, maxAbscissaValue - 2); low.setFont(ColorUtil.TITLE_FONT); medium.setFont(ColorUtil.TITLE_FONT); high.setFont(ColorUtil.TITLE_FONT); low.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); medium.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); high.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.addAnnotation(low); plot.addAnnotation(medium); plot.addAnnotation(high); for (int i = 0; i < xValues.size(); i++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xValues.get(i).getScriptLabel(), (yValues.get(i).getPercentage() * 100), (xValues.get(i).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); plot.addAnnotation(itemLabel); } if (null != xExcludedValues) { for (int j = 0; j < xExcludedValues.size(); j++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xExcludedValues.get(j).getScriptLabel(), (yExcludedValues.get(j).getPercentage() * 100), (xExcludedValues.get(j).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); plot.addAnnotation(itemLabel); } } return lineChart; }