List of usage examples for org.jfree.chart.plot XYPlot addRangeMarker
public void addRangeMarker(Marker marker)
From source file:bicat.gui.GraphicPane.java
public org.jfree.chart.JFreeChart newSimpleGraphic(double discretizationThr, boolean two_sided) { // this.remove(chartPanel); org.jfree.data.xy.XYSeries[] series = new org.jfree.data.xy.XYSeries[graphDataList.size()]; gProfiles = new org.jfree.data.xy.DefaultTableXYDataset(); // System.out.println("Created empty gene // expressions...."+graphDataList.size()); for (int j = 0; j < graphDataList.size(); j++) { series[j] = new org.jfree.data.xy.XYSeries("Gene Profile " + j + "", true, false); float[] expressions = (float[]) graphDataList.get(j); for (int i = 0; i < expressions.length; i++) series[j].add(i, expressions[i]); gProfiles.addSeries(series[j]);/*from w w w . j a va2s .c o m*/ expressions = null; } chart = null; double[] chips = new double[chipList.size()]; for (int p = 0; p < chips.length; p++) chips[p] = ((Integer) chipList.get(p)).doubleValue(); chart = myCreateSimpleXYLineChart(null, null, null, gProfiles, chips, org.jfree.chart.plot.PlotOrientation.VERTICAL, // HORIZONTAL, true, true, false); org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) chart.getPlot(); // ADD THE DISCRETIZATION THRESHOLD MARKS org.jfree.chart.plot.ValueMarker up_thr_marker = new org.jfree.chart.plot.ValueMarker(discretizationThr); up_thr_marker.setPaint(Color.RED); xyPlot.addRangeMarker(up_thr_marker); if (two_sided) { org.jfree.chart.plot.ValueMarker down_thr_marker = new org.jfree.chart.plot.ValueMarker( 0 - discretizationThr); down_thr_marker.setPaint(Color.RED); xyPlot.addRangeMarker(down_thr_marker); } // xyPlot.setDomainCrosshairVisible(false); // xyPlot.setRangeCrosshairVisible(false); /* * xyPlot.zoomHorizontalAxes(2.0); xyPlot.zoomVerticalAxes(2.0); */ return chart; }
From source file:com.bdb.weather.display.day.DayTemperaturePane.java
@Override public void addExtremeMarkers(XYPlot plot, DailyRecords records, WeatherAverage averages) { if (minMaxLabelsItem.isSelected()) { String unit = Temperature.getDefaultUnit().toString(); if (records != null) { recordHigh = records.getMaxHighTemperature(); ValueMarker marker = new ValueMarker(recordHigh.get()); marker.setLabel("Record High " + recordHigh.toString() + " " + unit + " (" + records.getMaxHighTemperatureYear() + ")"); marker.setLabelTextAnchor(TextAnchor.BASELINE_LEFT); marker.setPaint(//from ww w .ja v a2 s. c om StageUtilities.toAwtColor(ColorPreferences.getInstance().getHighOutdoorTempColorPref())); plot.addRangeMarker(marker); recordLow = records.getMinLowTemperature(); marker = new ValueMarker(recordLow.get()); marker.setLabel("Record Low " + recordLow.toString() + " " + unit + " (" + records.getMinLowTemperatureYear() + ")"); marker.setLabelTextAnchor(TextAnchor.BASELINE_LEFT); marker.setPaint( StageUtilities.toAwtColor(ColorPreferences.getInstance().getLowOutdoorTempColorPref())); plot.addRangeMarker(marker); } if (averages != null) { Temperature value = averages.getHighTemperature(); ValueMarker marker = new ValueMarker(value.get()); marker.setLabel("Average High " + value.toString() + " " + unit); marker.setLabelTextAnchor(TextAnchor.BASELINE_LEFT); marker.setPaint( StageUtilities.toAwtColor(ColorPreferences.getInstance().getHighOutdoorTempColorPref())); plot.addRangeMarker(marker); value = averages.getLowTemperature(); marker = new ValueMarker(value.get()); marker.setLabel("Average Low " + value.toString() + " " + unit); marker.setLabelTextAnchor(TextAnchor.BASELINE_LEFT); marker.setPaint( StageUtilities.toAwtColor(ColorPreferences.getInstance().getLowOutdoorTempColorPref())); plot.addRangeMarker(marker); } } }
From source file:net.sf.maltcms.chromaui.foldChangeViewer.tasks.FoldChangeViewLoaderWorker.java
@Override public void run() { ProgressHandle handle = ProgressHandleFactory.createHandle("Creating fold change plot"); try {// w w w . java 2 s. c o m handle.setDisplayName("Loading fold change elements");//+new File(this.files.getResourceLocation()).getName()); handle.start(5); handle.progress("Reading settings", 1); RTUnit rtAxisUnit = RTUnit.valueOf(sp.getProperty("rtAxisUnit", "SECONDS")); handle.progress("Retrieving data", 2); XYShapeRenderer renderer = new XYShapeRenderer() { @Override protected Paint getPaint(XYDataset dataset, int series, int item) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Math.abs(x) < 1.0) { Paint p = super.getPaint(dataset, series, item); if (p instanceof Color) { Color color = (Color) p; float[] values = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); Color hsb = new Color( Color.HSBtoRGB(values[0], (float) Math.max(0.1, values[1] - 0.9), values[2])); return new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), 64); } } return super.getPaint(dataset, series, item); } }; renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesOutlinePaint(true); renderer.setBaseCreateEntities(true); handle.progress("Building plot", 3); XYPlot plot = new XYPlot(dataset, new NumberAxis("log2 fold change"), new NumberAxis("-log10 p-value"), renderer); BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, new float[] { 5.0f }, 0.0f); ValueMarker marker = new ValueMarker(-Math.log10(0.05), Color.RED, dashed); marker.setLabel("p-value=0.05"); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); marker.setLabelOffset(new RectangleInsets(UnitType.ABSOLUTE, 0, 50, 10, 0)); marker.setLabelOffsetType(LengthAdjustmentType.EXPAND); marker.setLabelPaint(Color.LIGHT_GRAY); plot.addRangeMarker(marker); Font font1 = new Font("SansSerif", Font.PLAIN, 12); SelectionAwareXYTooltipGenerator tooltipGenerator = cvtc.getLookup() .lookup(SelectionAwareXYTooltipGenerator.class); if (tooltipGenerator == null) { tooltipGenerator = new SelectionAwareXYTooltipGenerator(tooltipGenerator) { @Override public String createSelectionAwareTooltip(XYDataset xyd, int i, int i1) { FoldChangeDataset dataset = (FoldChangeDataset) xyd; FoldChangeElement fce = dataset.getNamedElementProvider().get(i).get(i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(fce.getPeakGroup().getMajorityDisplayName()); sb.append("<br>"); sb.append("log2 fold change="); sb.append(fce.getFoldChange()); sb.append("<br>"); sb.append("p-value="); sb.append(Math.pow(10, -fce.getPvalue())); sb.append("</html>"); return sb.toString(); } }; } tooltipGenerator.setXYToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(comp); sb.append("<br>"); sb.append("log2 fold change="); sb.append(x); sb.append("<br>"); sb.append("p-value="); sb.append(sb.append(Math.pow(10, -y))); sb.append("</html>"); return sb.toString(); } }); plot.getRenderer().setBaseToolTipGenerator(tooltipGenerator); handle.progress("Configuring plot", 4); configurePlot(plot, rtAxisUnit); final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); Range domainRange = null; Range valueRange = null; if (cmhp != null) { XYPlot xyplot = cmhp.getPlot(); if (xyplot != null) { ValueAxis domain = xyplot.getDomainAxis(); domainRange = domain.getRange(); ValueAxis range = xyplot.getRangeAxis(); valueRange = range.getRange(); } } if (domainRange != null) { plot.getDomainAxis().setRange(domainRange); } if (valueRange != null) { Logger.getLogger(getClass().getName()).info("Setting previous value range!"); } handle.progress("Adding plot to panel", 5); final XYPlot targetPlot = plot; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); cmhp.setPlot(targetPlot); cvtc.requestActive(); } }); } finally { handle.finish(); } }
From source file:org.jfree.chart.demo.MarkerDemo1.java
/** * Creates a sample chart./* w ww .j a v a2s . c om*/ * * @param data the sample data. * * @return A configured chart. */ private JFreeChart createChart(final XYDataset data) { final JFreeChart chart = ChartFactory.createScatterPlot("Marker Demo 1", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // chart.getLegend().setAnchor(Legend.EAST); // customise... final XYPlot plot = chart.getXYPlot(); plot.getRenderer().setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); // set axis margins to allow space for marker labels... final DateAxis domainAxis = new DateAxis("Time"); domainAxis.setUpperMargin(0.50); plot.setDomainAxis(domainAxis); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.30); rangeAxis.setLowerMargin(0.50); // add a labelled marker for the bid start price... final Marker start = new ValueMarker(200.0); start.setPaint(Color.green); start.setLabel("Bid Start Price"); start.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); start.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(start); // add a labelled marker for the target price... final Marker target = new ValueMarker(175.0); target.setPaint(Color.red); target.setLabel("Target Price"); target.setLabelAnchor(RectangleAnchor.TOP_RIGHT); target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addRangeMarker(target); // add a labelled marker for the original closing time... final Hour hour = new Hour(2, new Day(22, 5, 2003)); double millis = hour.getFirstMillisecond(); final Marker originalEnd = new ValueMarker(millis); originalEnd.setPaint(Color.orange); originalEnd.setLabel("Original Close (02:00)"); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(originalEnd); // add a labelled marker for the current closing time... final Minute min = new Minute(15, hour); millis = min.getFirstMillisecond(); final Marker currentEnd = new ValueMarker(millis); currentEnd.setPaint(Color.red); currentEnd.setLabel("Close Date (02:15)"); currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addDomainMarker(currentEnd); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // label the best bid with an arrow and label... final Hour h = new Hour(2, new Day(22, 5, 2003)); final Minute m = new Minute(10, h); millis = m.getFirstMillisecond(); final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null); final XYAnnotation bestBid = new XYDrawableAnnotation(millis, 163.0, 11, 11, cd); plot.addAnnotation(bestBid); final XYPointerAnnotation pointer = new XYPointerAnnotation("Best Bid", millis, 163.0, 3.0 * Math.PI / 4.0); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); plot.addAnnotation(pointer); return chart; }
From source file:bicat.gui.GraphicPane.java
public void updateGraphic(double[] discretizationThr, boolean two_sided) { org.jfree.data.xy.XYSeries[] series = new org.jfree.data.xy.XYSeries[graphDataList.size()]; // = // new/*from w w w. ja v a 2 s. co m*/ // org.jfree.data.xy.XYSeries("Gene // Profile",true,false); gProfiles = new org.jfree.data.xy.DefaultTableXYDataset(); if (MethodConstants.debug) { System.out.println("2. Created empty gene expressions...." + graphDataList.size()); } int usedSize = 0; if (graphDataList.size() > MAXIMUM_SIZE) usedSize = MAXIMUM_SIZE; else usedSize = graphDataList.size(); for (int j = 0; j < usedSize; j++) { // if(owner.debug) System.out.println("\n\nNew profile: "); Object currGene = geneList.get(j); Integer currentGeneInt = (Integer) currGene; String currentGeneName = engine.getCurrentDataset().getGeneName(currentGeneInt.intValue()); series[j] = new org.jfree.data.xy.XYSeries("Gene " + currentGeneName + "", true, false); float[] expressions = (float[]) graphDataList.get(j); for (int i = 0; i < expressions.length; i++) { /* * if(chipList.contains(new Integer(i))) series[j].add(i, * expressions[i] - 1); //-owner.CONTRAST_VALUE); else */ series[j].add(i, expressions[i]); // if(owner.debug) System.out.print(expressions[i]+", "); } gProfiles.addSeries(series[j]); // series.clear(); expressions = null; } chart = null; double[] chips = new double[chipList.size()]; for (int p = 0; p < chips.length; p++) chips[p] = ((Integer) chipList.get(p)).doubleValue(); chart = myCreateXYLineChart("Expression profiles of Bicluster", "conditions", "gene expression", gProfiles, chips, org.jfree.chart.plot.PlotOrientation.VERTICAL, // HORIZONTAL, true, true, false); org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) chart.getPlot(); // xyPlot.addRangeMarker(new org.jfree.chart.plot.ValueMarker(10.0)); // ADD THE DISCRETIZATION THRESHOLD MARKS! for (int i = 0; i < discretizationThr.length; i++) { org.jfree.chart.plot.ValueMarker up_thr_marker = new org.jfree.chart.plot.ValueMarker( discretizationThr[i]); up_thr_marker.setPaint(Color.RED); xyPlot.addRangeMarker(up_thr_marker); if (two_sided) { org.jfree.chart.plot.ValueMarker down_thr_marker = new org.jfree.chart.plot.ValueMarker( 0 - discretizationThr[i]); down_thr_marker.setPaint(Color.RED); xyPlot.addRangeMarker(down_thr_marker); } } // chart.plotChanged(null) // owner.graphScrollPane.repaint(); chartPanel = new org.jfree.chart.ChartPanel(chart); // ChartPanel(chart); this.removeAll(); this.add(chartPanel); this.setVisible(true); chartPanel.revalidate(); /* * owner.graphViewPane.removeAll(); * owner.graphViewPane.add(owner.graphInfoLabel); * owner.graphViewPane.add(this); */ }
From source file:org.openmrs.web.servlet.ShowGraphServlet.java
/** * The main method for this class. It will create a JFreeChart object to be written to the * response./*ww w . jav a 2 s . co m*/ * * @param request the current request will all the parameters needed * @return JFreeChart object to be rendered * @should set value axis label to given units * @should set value axis label to concept numeric units if given units is null */ protected JFreeChart getChart(HttpServletRequest request) { // All available GET parameters String patientId = request.getParameter("patientId"); // required String conceptId1 = request.getParameter("conceptId"); // required String conceptId2 = request.getParameter("conceptId2"); String chartTitle = request.getParameter("chartTitle"); String units = request.getParameter("units"); String minRangeString = request.getParameter("minRange"); String maxRangeString = request.getParameter("maxRange"); String hideDate = request.getParameter("hideDate"); Patient patient = Context.getPatientService().getPatient(Integer.parseInt(patientId)); // Set date range to passed values, otherwise set a default date range to the last 12 months Calendar cal = Calendar.getInstance(); Date fromDate = getFromDate(request.getParameter("fromDate")); Date toDate = getToDate(request.getParameter("toDate")); // Swap if fromDate is after toDate if (fromDate.getTime() > toDate.getTime()) { Long temp = fromDate.getTime(); fromDate.setTime(toDate.getTime()); toDate.setTime(temp); } // Graph parameters Double minRange = null; Double maxRange = null; Double normalLow = null; Double normalHigh = null; Double criticalLow = null; Double criticalHigh = null; String timeAxisTitle = null; String rangeAxisTitle = null; boolean userSpecifiedMaxRange = false; boolean userSpecifiedMinRange = false; // Fetching obs List<Obs> observations1 = new ArrayList<Obs>(); List<Obs> observations2 = new ArrayList<Obs>(); Concept concept1 = null, concept2 = null; if (conceptId1 != null) { concept1 = Context.getConceptService().getConcept(Integer.parseInt(conceptId1)); } if (conceptId2 != null) { concept2 = Context.getConceptService().getConcept(Integer.parseInt(conceptId2)); } if (concept1 != null) { observations1 = Context.getObsService().getObservationsByPersonAndConcept(patient, concept1); chartTitle = concept1.getName().getName(); rangeAxisTitle = ((ConceptNumeric) concept1).getUnits(); minRange = ((ConceptNumeric) concept1).getLowAbsolute(); maxRange = ((ConceptNumeric) concept1).getHiAbsolute(); normalLow = ((ConceptNumeric) concept1).getLowNormal(); normalHigh = ((ConceptNumeric) concept1).getHiNormal(); criticalLow = ((ConceptNumeric) concept1).getLowCritical(); criticalHigh = ((ConceptNumeric) concept1).getHiCritical(); // Only get observations2 if both concepts share the same units; update chart title and ranges if (concept2 != null) { String concept2Units = ((ConceptNumeric) concept2).getUnits(); if (concept2Units != null && concept2Units.equals(rangeAxisTitle)) { observations2 = Context.getObsService().getObservationsByPersonAndConcept(patient, concept2); chartTitle += " + " + concept2.getName().getName(); if (((ConceptNumeric) concept2).getHiAbsolute() != null && ((ConceptNumeric) concept2).getHiAbsolute() > maxRange) { maxRange = ((ConceptNumeric) concept2).getHiAbsolute(); } if (((ConceptNumeric) concept2).getLowAbsolute() != null && ((ConceptNumeric) concept2).getLowAbsolute() < minRange) { minRange = ((ConceptNumeric) concept2).getLowAbsolute(); } } else { log.warn("Units for concept id: " + conceptId2 + " don't match units for concept id: " + conceptId1 + ". Only displaying " + conceptId1); concept2 = null; // nullify concept2 so that the legend isn't shown later } } } else { chartTitle = "Concept " + conceptId1 + " not found"; rangeAxisTitle = "Value"; } // Overwrite with user-specified values, otherwise use default values if (units != null && units.length() > 0) { rangeAxisTitle = units; } if (minRangeString != null) { minRange = Double.parseDouble(minRangeString); userSpecifiedMinRange = true; } if (maxRangeString != null) { maxRange = Double.parseDouble(maxRangeString); userSpecifiedMaxRange = true; } if (chartTitle == null) { chartTitle = ""; } if (rangeAxisTitle == null) { rangeAxisTitle = ""; } if (minRange == null) { minRange = 0.0; } if (maxRange == null) { maxRange = 200.0; } // Create data set TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries series1, series2; // Interval-dependent units Class<? extends RegularTimePeriod> timeScale = null; if (toDate.getTime() - fromDate.getTime() <= 86400000) { // Interval <= 1 day: minutely timeScale = Minute.class; timeAxisTitle = "Time"; } else if (toDate.getTime() - fromDate.getTime() <= 259200000) { // Interval <= 3 days: hourly timeScale = Hour.class; timeAxisTitle = "Time"; } else { timeScale = Day.class; timeAxisTitle = "Date"; } if (concept1 == null) { series1 = new TimeSeries("NULL", Hour.class); } else { series1 = new TimeSeries(concept1.getName().getName(), timeScale); } if (concept2 == null) { series2 = new TimeSeries("NULL", Hour.class); } else { series2 = new TimeSeries(concept2.getName().getName(), timeScale); } // Add data points for concept1 for (Obs obs : observations1) { if (obs.getValueNumeric() != null && obs.getObsDatetime().getTime() >= fromDate.getTime() && obs.getObsDatetime().getTime() < toDate.getTime()) { cal.setTime(obs.getObsDatetime()); if (timeScale == Minute.class) { Minute min = new Minute(cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series1.addOrUpdate(min, obs.getValueNumeric()); } else if (timeScale == Hour.class) { Hour hour = new Hour(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series1.addOrUpdate(hour, obs.getValueNumeric()); } else { Day day = new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series1.addOrUpdate(day, obs.getValueNumeric()); } } } // Add data points for concept2 for (Obs obs : observations2) { if (obs.getValueNumeric() != null && obs.getObsDatetime().getTime() >= fromDate.getTime() && obs.getObsDatetime().getTime() < toDate.getTime()) { cal.setTime(obs.getObsDatetime()); if (timeScale == Minute.class) { Minute min = new Minute(cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series2.addOrUpdate(min, obs.getValueNumeric()); } else if (timeScale == Hour.class) { Hour hour = new Hour(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series2.addOrUpdate(hour, obs.getValueNumeric()); } else { Day day = new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series2.addOrUpdate(day, obs.getValueNumeric()); } } } // Add series to dataset dataset.addSeries(series1); if (!series2.isEmpty()) { dataset.addSeries(series2); } // As of JFreeChart 1.0.11 the default background color is dark grey instead of white. // This line restores the original white background. ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart chart = null; // Show legend only if more than one series if (concept2 == null) { chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisTitle, rangeAxisTitle, dataset, false, false, false); } else { chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisTitle, rangeAxisTitle, dataset, true, false, false); } // Customize title font Font font = new Font("Arial", Font.BOLD, 12); TextTitle title = chart.getTitle(); title.setFont(font); chart.setTitle(title); // Add subtitle, unless 'hideDate' has been passed if (hideDate == null) { TextTitle subtitle = new TextTitle(fromDate.toString() + " - " + toDate.toString()); subtitle.setFont(font); chart.addSubtitle(subtitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("No Data Available"); // Add abnormal/critical range background color (only for single-concept graphs) if (concept2 == null) { IntervalMarker abnormalLow, abnormalHigh, critical; if (normalHigh != null) { abnormalHigh = new IntervalMarker(normalHigh, maxRange, COLOR_ABNORMAL); plot.addRangeMarker(abnormalHigh); } if (normalLow != null) { abnormalLow = new IntervalMarker(minRange, normalLow, COLOR_ABNORMAL); plot.addRangeMarker(abnormalLow); } if (criticalHigh != null) { critical = new IntervalMarker(criticalHigh, maxRange, COLOR_CRITICAL); plot.addRangeMarker(critical); } if (criticalLow != null) { critical = new IntervalMarker(minRange, criticalLow, COLOR_CRITICAL); plot.addRangeMarker(critical); } // there is data outside of the absolute lower limits for this concept (or of what the user specified as minrange) if (plot.getRangeAxis().getLowerBound() < minRange) { IntervalMarker error = new IntervalMarker(plot.getRangeAxis().getLowerBound(), minRange, COLOR_ERROR); plot.addRangeMarker(error); } if (plot.getRangeAxis().getUpperBound() > maxRange) { IntervalMarker error = new IntervalMarker(maxRange, plot.getRangeAxis().getUpperBound(), COLOR_ERROR); plot.addRangeMarker(error); } } // Visuals XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(true); } // Customize the plot (range and domain axes) // Modify x-axis (datetime) DateAxis timeAxis = (DateAxis) plot.getDomainAxis(); if (timeScale == Day.class) { timeAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy")); } timeAxis.setRange(fromDate, toDate); // Set y-axis range (values) NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (userSpecifiedMinRange) { minRange = (rangeAxis.getLowerBound() < minRange) ? rangeAxis.getLowerBound() : minRange; } if (userSpecifiedMaxRange) { // otherwise we just use default range maxRange = (rangeAxis.getUpperBound() > maxRange) ? rangeAxis.getUpperBound() : maxRange; } rangeAxis.setRange(minRange, maxRange); return chart; }
From source file:jboost.visualization.HistogramFrame.java
private JFreeChart createRocChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart("ROC", // chart title "False positive rate", // x axis label "True positive rate", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include // legend true, // tooltips false // urls );/*w w w. j a va 2s .c o m*/ chart.setAntiAlias(false); RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); chart.setRenderingHints(hints); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); lower_tprMarker = new ValueMarker(0.5); lower_tprMarker.setPaint(Color.blue); lower_fprMarker = new ValueMarker(0.5); lower_fprMarker.setPaint(Color.blue); plot.addRangeMarker(lower_tprMarker); plot.addDomainMarker(lower_fprMarker); upper_tprMarker = new ValueMarker(0.5); upper_tprMarker.setPaint(Color.red); upper_fprMarker = new ValueMarker(0.5); upper_fprMarker.setPaint(Color.red); plot.addRangeMarker(upper_tprMarker); plot.addDomainMarker(upper_fprMarker); return chart; }
From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java
private void chartDrawHerizonLine(VACVBSMetaData data, Color color, String Labelstr) { XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); final Marker start = new ValueMarker(0); start.setPaint(color);/* w ww.j av a2 s .co m*/ start.setLabel(Labelstr); start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); start.setLabelTextAnchor(TextAnchor.TOP_LEFT); start.setLabelPaint(color); plot.addRangeMarker(start); }
From source file:sanger.team16.gui.genevar.eqtl.snp.RegionalLinePlot.java
private JFreeChart createChart(String chromosome, int position, int distance, double threshold, XYDataset dataset) {/*w w w . j a v a2 s .co m*/ JFreeChart chart = ChartFactory.createXYLineChart(null, "Position on chromosome " + chromosome + " (bp)", "-log10(P)", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); //renderer.setShapesFilled(false); //CHANGED 12/12/11 // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); /* XYItemRenderer renderer = plot.getRenderer(); int size = dataset.getSeriesCount(); for (int i=0 ; i<size ; i++) { //renderer.setSeriesPaint(i, new Color(255, 0, 0)); renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3)); renderer.setBaseSeriesVisibleInLegend(false); } */ ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold)); upperMarker.setPaint(Color.gray); float[] f = { 4, 3, 4, 3 }; upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f)); plot.addRangeMarker(upperMarker); ValueMarker marker = new ValueMarker(0.0); marker.setPaint(Color.lightGray); plot.addRangeMarker(marker); XYSeries series = new XYSeries("Range"); series.add(position - distance, -0.05); series.add(position + distance, -0.05); ((XYSeriesCollection) dataset).addSeries(series); renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false); return chart; }
From source file:api3.transform.PlotWave.java
public void plot(double[][] signal, String name, long samplerate) { frame.setTitle(name);//from w w w . j a va 2 s . c o m XYSeries[] soundWave = new XYSeries[signal.length]; for (int j = 0; j < signal.length; ++j) { soundWave[j] = new XYSeries("sygnal" + j); for (int i = 0; i < signal[0].length; ++i) { double index = (samplerate == 0) ? i : 1000.0 * (double) i / (double) samplerate; soundWave[j].add(index, signal[j][i]); } } XYSeriesCollection dataset = new XYSeriesCollection(); for (int j = 0; j < signal.length; ++j) { dataset.addSeries(soundWave[j]); } JFreeChart chart = // (samplerate ==0 )? // ChartFactory.createXYBarChart( // name, // "prbka", // false, // "warto", // new XYBarDataset(dataset,0.0625), // PlotOrientation.VERTICAL, // true,false,false) // : ChartFactory.createXYLineChart(name, "prbka", "warto", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { int value = slider.getValue(); double minimum = domainAxis.getRange().getLowerBound(); double maximum = domainAxis.getRange().getUpperBound(); double delta = (0.1f * (domainAxis.getRange().getLength())); if (value < lastValue) { // left minimum = minimum - delta; maximum = maximum - delta; } else { // right minimum = minimum + delta; maximum = maximum + delta; } DateRange range = new DateRange(minimum, maximum); domainAxis.setRange(range); lastValue = value; if (lastValue == slider.getMinimum() || lastValue == slider.getMaximum()) { slider.setValue(SLIDER_DEFAULT_VALUE); } } }); plot.addRangeMarker(new ValueMarker(0, Color.BLACK, new BasicStroke(1))); ChartPanel chartPanel = new ChartPanel(chart); Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder()); chartPanel.setBorder(border); chartPanel.addMouseWheelListener(addZoomWheel()); panel.add(chartPanel); JPanel dashboard = new JPanel(new BorderLayout()); dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4)); dashboard.add(slider); panel.add(dashboard, BorderLayout.SOUTH); frame.getContentPane().add((JPanel) panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }