List of usage examples for org.jfree.chart JFreeChart setAntiAlias
public void setAntiAlias(boolean flag)
From source file:mzmatch.ipeak.normalisation.VanDeSompele.java
public static void main(String args[]) { try {/* w w w . ja va 2s . c o m*/ Tool.init(); // parse the commandline options 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 { // if the output directories do not exist, create them if (options.output != null) Tool.createFilePath(options.output, true); } // load the data if (options.verbose) System.out.println("Loading data"); ParseResult result = PeakMLParser.parse(new FileInputStream(options.input), true); Header header = result.header; IPeakSet<IPeakSet<? extends IPeak>> peaksets = (IPeakSet<IPeakSet<? extends IPeak>>) result.measurement; int nrmeasurements = header.getNrMeasurementInfos(); // remove the stability factor annotation for (IPeak peak : peaksets) peak.removeAnnotation("stability factor"); // load the database if (options.verbose) System.out.println("Loading the molecule database"); HashMap<String, Molecule> database = MoleculeIO.parseXml(new FileInputStream(options.database)); // filter the set to include only identifiable metabolites if (options.verbose) System.out.println("Creating selection"); Vector<IPeakSet<? extends IPeak>> selection = new Vector<IPeakSet<? extends IPeak>>(); for (Molecule molecule : database.values()) { double mass = molecule.getMass(Mass.MONOISOTOPIC); double delta = PeriodicTable.PPM(mass, options.ppm); // get the most intense peak containing all the measurements Vector<IPeakSet<? extends IPeak>> neighbourhoud = peaksets.getPeaksInMassRange(mass - delta, mass + delta); Collections.sort(neighbourhoud, IPeak.sort_intensity_descending); for (IPeakSet<? extends IPeak> neighbour : neighbourhoud) if (count(neighbour) == nrmeasurements) { selection.add(neighbour); break; } } // calculate the stability factor for each peak in the selection if (options.verbose) System.out.println("Calculating stability factors"); for (int peakid1 = 0; peakid1 < selection.size(); ++peakid1) { double stddeviations[] = new double[selection.size()]; IPeakSet<? extends IPeak> peakset1 = selection.get(peakid1); for (int peakid2 = 0; peakid2 < selection.size(); ++peakid2) { IPeakSet<? extends IPeak> peakset2 = selection.get(peakid2); double values[] = new double[nrmeasurements]; for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) { int measurementid1 = peakset1.get(measurementid).getMeasurementID(); int setid1 = header.indexOfSetInfo(header.getSetInfoForMeasurementID(measurementid1)); int measurementid2 = peakset2.get(measurementid).getMeasurementID(); int setid2 = header.indexOfSetInfo(header.getSetInfoForMeasurementID(measurementid2)); if (setid1 != setid2 || measurementid1 != measurementid2) System.err.println("[WARNING]: differing setid or spectrumid for comparison"); values[measurementid] = Math.log(peakset1.get(measurementid).getIntensity() / peakset2.get(measurementid).getIntensity()) / Math.log(2); } stddeviations[peakid2] = Statistical.stddev(values); } peakset1.addAnnotation("stability factor", Statistical.mean(stddeviations)); } // sort on the stability factor Collections.sort(selection, new IPeak.AnnotationAscending("stability factor")); // take the top 10% and calculate the geometric mean if (options.verbose) System.out.println("Calculating normalisation factors"); int nrselected = (int) (0.1 * selection.size()); if (nrselected < 10) nrselected = (10 < selection.size() ? 10 : selection.size()); double normalization_factors[] = new double[nrmeasurements]; for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) { double values[] = new double[nrselected]; for (int i = 0; i < nrselected; ++i) { IPeak peak = selection.get(i).get(measurementid); values[i] = peak.getIntensity(); } normalization_factors[measurementid] = Statistical.geomean(values); } // scale the found normalization factors double maxnf = Statistical.max(normalization_factors); for (int sampleid = 0; sampleid < nrmeasurements; ++sampleid) normalization_factors[sampleid] /= maxnf; // write the selection if needed if (options.selection != null) { if (options.verbose) System.out.println("Writing original selection data"); PeakMLWriter.write(result.header, selection, null, new GZIPOutputStream(new FileOutputStream(options.selection)), null); } // normalize all the peaks if (options.verbose) System.out.println("Normalizing all the entries"); for (IPeakSet<? extends IPeak> peakset : peaksets) { for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) { // TODO why did I do this again ? int id = 0; int setid = 0; int spectrumid = 0; for (int i = 0; i < header.getNrSetInfos(); ++i) { SetInfo set = header.getSetInfos().get(i); if (id + set.getNrMeasurementIDs() > measurementid) { setid = i; spectrumid = measurementid - id; break; } else id += set.getNrMeasurementIDs(); } MassChromatogram<Peak> masschromatogram = null; for (IPeak p : peakset) { int mymeasurementid = p.getMeasurementID(); int mysetid = header.indexOfSetInfo(header.getSetInfoForMeasurementID(mymeasurementid)); if (mysetid == setid && mymeasurementid == spectrumid) { masschromatogram = (MassChromatogram<Peak>) p; break; } } if (masschromatogram == null) continue; for (IPeak peak : masschromatogram.getPeaks()) peak.setIntensity(peak.getIntensity() / normalization_factors[measurementid]); } } // write the selection if needed if (options.selection_normalized != null) { if (options.verbose) System.out.println("Writing the normalized selection data"); PeakMLWriter.write(result.header, selection, null, new GZIPOutputStream(new FileOutputStream(options.selection_normalized)), null); } // write the factors if needed if (options.factors != null) { if (options.verbose) System.out.println("Writing the normalization factors"); PrintStream out = new PrintStream(options.factors); for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) out.println(header.getMeasurementInfo(measurementid).getLabel() + "\t" + normalization_factors[measurementid]); } // write the plot if needed if (options.img != null) { if (options.verbose) System.out.println("Writing the graph"); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart linechart = ChartFactory.createLineChart(null, "measurement", "normalization factor", dataset, PlotOrientation.VERTICAL, false, // legend false, // tooltips false // urls ); CategoryPlot plot = (CategoryPlot) linechart.getPlot(); CategoryAxis axis = (CategoryAxis) plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesShapesFilled(0, true); renderer.setSeriesShapesVisible(0, true); linechart.setBackgroundPaint(Color.WHITE); linechart.setBorderVisible(false); linechart.setAntiAlias(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); // create the datasets for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) dataset.addValue(normalization_factors[measurementid], "", header.getMeasurementInfo(measurementid).getLabel()); JFreeChartTools.writeAsPDF(new FileOutputStream(options.img), linechart, 800, 500); } // write the normalized values if (options.verbose) System.out.println("Writing the normalized data"); PeakMLWriter.write(result.header, peaksets.getPeaks(), null, new GZIPOutputStream(new FileOutputStream(options.output)), null); } catch (Exception e) { Tool.unexpectedError(e, application); } }
From source file:mzmatch.ipeak.align.CowCoda.java
@SuppressWarnings("unchecked") public static void main(String args[]) { final String lbl_mcq = "mcq"; try {//from ww w .j a v a2s . 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:com.spotify.heroic.http.render.RenderUtils.java
public static JFreeChart createChart(final List<ShardedResultGroup> groups, final String title, Map<String, String> highlight, Double threshold, int height) { final XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer(true, true); final DeviationRenderer intervalRenderer = new DeviationRenderer(); final XYSeriesCollection regularData = new XYSeriesCollection(); final YIntervalSeriesCollection intervalData = new YIntervalSeriesCollection(); int lineAndShapeCount = 0; int intervalCount = 0; for (final ShardedResultGroup resultGroup : groups) { final MetricCollection group = resultGroup.getMetrics(); if (group.getType() == MetricType.POINT) { final XYSeries series = new XYSeries(resultGroup.getMetrics().toString()); final List<Point> data = group.getDataAs(Point.class); for (final Point d : data) { series.add(d.getTimestamp(), d.getValue()); }// w ww .j av a 2s .c o m lineAndShapeRenderer.setSeriesPaint(lineAndShapeCount, Color.BLUE); lineAndShapeRenderer.setSeriesShapesVisible(lineAndShapeCount, false); lineAndShapeRenderer.setSeriesStroke(lineAndShapeCount, new BasicStroke(2.0f)); regularData.addSeries(series); ++lineAndShapeCount; } if (group.getType() == MetricType.SPREAD) { final YIntervalSeries series = new YIntervalSeries(resultGroup.getMetrics().toString()); final List<Spread> data = group.getDataAs(Spread.class); for (final Spread d : data) { series.add(d.getTimestamp(), d.getSum() / d.getCount(), d.getMin(), d.getMax()); } intervalRenderer.setSeriesPaint(intervalCount, Color.GREEN); intervalRenderer.setSeriesStroke(intervalCount, new BasicStroke(2.0f)); intervalRenderer.setSeriesFillPaint(intervalCount, new Color(200, 255, 200)); intervalRenderer.setSeriesShapesVisible(intervalCount, false); intervalData.addSeries(series); ++intervalCount; } } final JFreeChart chart = buildChart(title, regularData, intervalData, lineAndShapeRenderer, intervalRenderer); chart.setAntiAlias(true); chart.setBackgroundPaint(Color.WHITE); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); if (threshold != null) { final ValueMarker marker = new ValueMarker(threshold, Color.RED, new BasicStroke(Math.max(Math.min(height / 20, 6), 1)), Color.RED, null, 0.5f); plot.addRangeMarker(marker); } plot.setRenderer(lineAndShapeRenderer); // final DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); return chart; }
From source file:com.projity.pm.graphic.chart.ChartHelper.java
public static JFreeChart createChart(final XYDataset dataset, boolean bar, final XYDataset secondDataset) { JFreeChart chart; if (secondDataset != null) chart = createBarLineChart(dataset, secondDataset); else//from w ww . j av a 2s . co m chart = bar ? createBarChart(dataset) : createLineChart(dataset); chart.setAntiAlias(false);// faster chart.setBorderVisible(false); return chart; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC).// www .jav a 2s . co m * * @param bestFitness A linked hashmap mapping the NFC to the best fitness value * found so far. * @param fitnessFunction The name of the fitness function, used for the title and the * name of the file that is saved, e.g. "De Jong". */ public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) { /* Create an XYSeries plot */ XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls"); /* Add the NFC and best fitness value data to the series */ for (Integer NFC : bestFitness.keySet()) { /* Jfreechart crashes if double values are too large! */ if (bestFitness.get(NFC) <= 10E12) { series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue()); } } /* Add the x,y series data to the dataset */ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); /* Plot the data as an X,Y line chart */ JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls", "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false, true, false); /* Configure the chart settings such as anti-aliasing, background colour */ chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); /* Set the domain range from 0 to NFC */ NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue()); /* Logarithmic range axis */ plot.setRangeAxis(new LogAxis()); /* Set the thickness and colour of the lines */ XYItemRenderer renderer = plot.getRenderer(); BasicStroke thickLine = new BasicStroke(3.0f); renderer.setSeriesStroke(0, thickLine); renderer.setPaint(Color.BLACK); /* Display the plot in a JFrame */ ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart); frame.setVisible(true); frame.setSize(1000, 600); /* Save the plot as an image named after fitness function try { ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900); } catch (IOException e) { e.printStackTrace(); }*/ }
From source file:org.nbheaven.sqe.codedefects.dashboard.controlcenter.panels.Statistics.java
private static JFreeChart createOverviewPanel(DefaultCategoryDataset dataSet) { JFreeChart overview = org.jfree.chart.ChartFactory.createStackedBarChart(null, null, "CodeDefects", dataSet, PlotOrientation.HORIZONTAL, false, true, false); overview.setBorderVisible(false);/*from ww w . j a va 2s .co m*/ overview.setBackgroundPaint(Color.WHITE); overview.setAntiAlias(true); overview.setNotify(true); CategoryPlot overviewPlot = overview.getCategoryPlot(); overviewPlot.setRangeGridlinePaint(Color.BLACK); overviewPlot.setDomainGridlinePaint(Color.BLACK); overviewPlot.setBackgroundPaint(Color.WHITE); overviewPlot.setForegroundAlpha(0.7f); overviewPlot.setRangeAxisLocation(AxisLocation.getOpposite(overviewPlot.getRangeAxisLocation())); CategoryAxis domainAxis = overviewPlot.getDomainAxis(); domainAxis.setVisible(true); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setLabel(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); overviewPlot.setRangeAxis(rangeAxis); CategoryItemRenderer categoryItemRenderer = new StackedBarRenderer(); //3D(); // categoryItemRenderers[0].setPaint(Color.RED); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); categoryItemRenderer.setBaseItemLabelsVisible(true); overviewPlot.setRenderer(categoryItemRenderer); return overview; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static void setGeneralChartProperties(JFreeChart chart, ChartData chartData) { chart.setBackgroundPaint(ChartUtils.getColor(chartData.getBackground())); chart.getPlot().setBackgroundPaint(ChartUtils.getColor(chartData.getForeground())); chart.setTitle(chartData.getTitle()); chart.setAntiAlias(chartData.isAntialias()); // Alpha transparency (100% means opaque) if (chartData.getAlpha() < 100) { chart.getPlot().setForegroundAlpha((float) chartData.getAlpha() / 100); }/*from w w w . ja v a 2s .c o m*/ }
From source file:com.controlj.addon.gwttree.server.GraphServlet.java
/**<!====== getChart ======================================================> Generates the chart. Note that most of these options are not required for a simple chart, but we wanted to try to get a particular look that matched another charting package, so we went to some trouble to set a lot of non-standard options. In particular, the OpaqueBarRenderer3D is a non-standard renderer that gives much better looking 3D bars. <!=======================================================================>*/ private static JFreeChart getChart(DefaultCategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart3D("Integration Over Time", "24 Hour Period", "", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.black); chart.getTitle().setPaint(Color.white); chart.getTitle().setFont(new Font("Verdana", Font.BOLD, 20)); chart.setAntiAlias(true); chart.setTextAntiAlias(true);//from ww w . j a v a2 s .c om CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(1); OpaqueBarRenderer3D renderer = new OpaqueBarRenderer3D(); renderer.setItemMargin(0.1); plot.setRenderer(renderer); renderer.setSeriesPaint(0, new Color(116, 225, 118)); renderer.setSeriesPaint(1, new Color(245, 107, 107)); renderer.setSeriesPaint(2, new Color(250, 187, 107)); renderer.setSeriesPaint(3, new Color(72, 72, 238)); renderer.setSeriesPaint(4, new Color(184, 32, 157)); renderer.setDrawBarOutline(false); Font small = new Font("Verdana", Font.PLAIN, 12); Font big = new Font("Verdana", Font.BOLD, 14); renderer.setItemLabelPaint(Color.white); plot.getDomainAxis().setTickLabelPaint(Color.white); plot.getDomainAxis().setTickLabelFont(small); plot.getDomainAxis().setLabelPaint(Color.white); plot.getDomainAxis().setLabelFont(big); plot.getDomainAxis().setCategoryMargin(0.2); plot.getRangeAxis().setTickLabelPaint(Color.white); plot.getRangeAxis().setTickLabelFont(small); plot.getRangeAxis().setLabelPaint(Color.white); plot.getRangeAxis().setLabelFont(big); plot.setBackgroundPaint(Color.black); chart.getLegend().setBackgroundPaint(Color.black); chart.getLegend().setItemPaint(Color.white); chart.getLegend().setItemFont(big); return chart; }
From source file:ec.util.chart.swing.Charts.java
/** * A sparkline is a type of information graphic characterized by its small * size and high data density. Sparklines present trends and variations * associated with some measurement, such as average temperature or stock * market activity, in a simple and condensed way. Several sparklines are * often used together as elements of a small multiple.<br> * * {@link http://en.wikipedia.org/wiki/Sparkline} * * @param dataset//from w w w.j a v a 2s.c o m * @return * @author Philippe Charles */ @Nonnull public static JFreeChart createSparkLineChart(@Nonnull XYDataset dataset) { JFreeChart result = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); result.setBorderVisible(false); result.setBackgroundPaint(null); result.setAntiAlias(true); XYPlot plot = result.getXYPlot(); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setOutlineVisible(false); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); plot.setBackgroundPaint(null); ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false); return result; }
From source file:com.uttesh.pdfngreport.util.chart.ChartStyle.java
/** * this method will set the style theme for pie chart. * * @see org.jfree.chart.StandardChartTheme * @param chart//w w w.j ava 2 s . c o m */ public static void theme(JFreeChart chart) { String fontName = "Lucida Sans"; StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setTitlePaint(Color.decode("#4572a7")); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 16)); //title theme.setLargeFont(new Font(fontName, Font.BOLD, 15)); //axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 11)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); chart.setTextAntiAlias(true); chart.setAntiAlias(true); }