List of usage examples for org.jfree.chart.plot XYPlot addAnnotation
public void addAnnotation(XYAnnotation annotation)
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.ClinicalPlot.java
private void createGlyphsAndAddToPlot(XYPlot plot) { XYShapeAnnotation glyph;//from www. ja v a 2 s . com Shape glyphShape; Color glyphColor; ClinicalDataPoint clinicalPoint; String survivalLenStr; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { clinicalPoint = (ClinicalDataPoint) i.next(); x = clinicalPoint.getFactorValue(factor1); y = clinicalPoint.getFactorValue(factor2); if ((x != ClinicalDataPoint.MISSING_CLINICAL_FACTOR_VALUE) && (y != ClinicalDataPoint.MISSING_CLINICAL_FACTOR_VALUE)) { //Make this a triangle GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + 1.5f, yf - 1.5f); gp.lineTo(xf - 1.5f, yf - 1.5f); gp.closePath(); glyphShape = gp; //Rectangle2D.Double rect = new Rectangle2D.Double(); //rect.setFrameFromCenter(x,y, x+1,y+1); //glyphShape = rect; glyphColor = getColorForDataPoint(clinicalPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); if (clinicalPoint.getSurvivalInMonths() >= 0.0) { survivalLenStr = nf.format(clinicalPoint.getSurvivalInMonths()); } else { survivalLenStr = ""; } String tooltip = clinicalPoint.getPatientId() + " " + clinicalPoint.getDiseaseName() + " survivalMonths=" + survivalLenStr; glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } } }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private void _drawSelectedPoint(XYPlot xyplot, int position) { TrackPoint point = this.getTrack().getPointAt(position); // Strelicu crtamo samo ako je samo jedna tocka oznacena: if (this.startSelectedPoints < 0 || this.endSelectedPoints < 0 || this.startSelectedPoints == this.endSelectedPoints) { double angle = point.getAngle(); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("", point.getPosition(), //$NON-NLS-1$ point.getElevation(), Math.PI - angle); xypointerannotation.setTipRadius(3.0D); xypointerannotation.setBaseRadius(30); xypointerannotation.setTextAnchor(TextAnchor.BASELINE_RIGHT); xypointerannotation.setFont(GUIConstants.SANS_SERIF_11); if (angle > 0) { xypointerannotation.setPaint(Color.red); } else if (angle < 0) { xypointerannotation.setPaint(Color.green); } else {/*from w w w . ja v a 2s. c o m*/ xypointerannotation.setPaint(Color.gray); } xypointerannotation.setText((TrackProfilerMath.round(100 * angle, 1)) + " %"); //$NON-NLS-1$ xyplot.addAnnotation(xypointerannotation); } ValueMarker valuemarker = new ValueMarker(point.getPosition()); valuemarker.setLabelOffsetType(LengthAdjustmentType.NO_CHANGE); valuemarker.setStroke(new BasicStroke(1.0F)); if (this.startSelectedPoints != this.endSelectedPoints && position == this.startSelectedPoints) { valuemarker.setLabelPaint(Color.blue); valuemarker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); // Ispisuje udaljenost i kut: TrackPoint t1 = this.getTrack().getPointAt(this.startSelectedPoints); TrackPoint t2 = this.getTrack().getPointAt(this.endSelectedPoints); double distance3D = TrackProfilerMath.round(t1.getPosition() - t2.getPosition(), 1); String angle = Math.abs(TrackProfilerMath.round(t1.getAngle(t2) * 100, 1)) + "%"; //$NON-NLS-1$ String label = Message.get(Messages.SELECTED_DISTANCE_LABEL) + distance3D + ", " //$NON-NLS-1$ + Message.get(Messages.SELECTED_ANGLE_LABEL) + angle; valuemarker.setLabel(" " + label); //$NON-NLS-1$ valuemarker.setLabelFont(GUIConstants.SANS_SERIF_11); } xyplot.addDomainMarker(valuemarker); }
From source file:org.matsim.counts.algorithms.graphs.CountsSimRealPerHourGraph.java
/** * @param hour A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 a.m. ... *//* w w w . ja v a 2s . c o m*/ @Override public JFreeChart createChart(final int hour) { this.hour = hour; XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<String> tooltips = new ArrayList<String>(); List<Comp> comps = new Vector<Comp>(); Iterator<CountSimComparison> l_it = this.ccl_.iterator(); //int elementCounter=0; while (l_it.hasNext()) { CountSimComparison cc = l_it.next(); /* values with simVal==0.0 or countVal==0.0 are drawn on the x==1 or/and y==1-line * Such values are the result of a poor simulation run, but they can also represent * a valid result (closing summer road during winter time) * */ if (cc.getHour() == hour) { //elementCounter++; double realVal = 1.0; double simVal = 1.0; if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) { realVal = cc.getCountValue(); simVal = cc.getSimulationValue(); series.add(realVal, simVal); comps.add(new Comp(realVal, "link" + cc.getId() + ".html", "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal)); } else { realVal = Math.max(1.0, cc.getCountValue()); simVal = Math.max(1.0, cc.getSimulationValue()); series_outliers.add(realVal, simVal); } } //if } //while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); /* first we have to sort the vector according to the rendering ordering * (which is the x value). * REALLY??? After hours of searching no better solution found! * please help! */ Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "Volumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label "Sim Volumes [veh/h]", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); //regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); //outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } }); dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } }); dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); plot.getRangeAxis().setRange(1.0, 19000.0); plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:org.matsim.pt.counts.PtCountsSimRealPerHourGraph.java
/** * @param hour/*from w w w . j ava 2 s. c om*/ * A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 * a.m. ... */ @Override public JFreeChart createChart(final int hour) { this.hour = hour; XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<String> tooltips = new ArrayList<String>(); List<Comp> comps = new Vector<Comp>(); Iterator<CountSimComparison> l_it = this.ccl_.iterator(); // int elementCounter=0; while (l_it.hasNext()) { CountSimComparison cc = l_it.next(); /* * values with simVal==0.0 or countVal==0.0 are drawn on the x==1 * or/and y==1-line Such values are the result of a poor simulation * run, but they can also represent a valid result (closing summer * road during winter time) */ if (cc.getHour() == hour) { // elementCounter++; double realVal = 1.0; double simVal = 1.0; if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) { realVal = cc.getCountValue(); simVal = cc.getSimulationValue(); series.add(realVal, simVal); comps.add(new Comp(realVal, "link" + cc.getId() + ".html", "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal)); } else { realVal = Math.max(1.0, cc.getCountValue()); simVal = Math.max(1.0, cc.getSimulationValue()); series_outliers.add(realVal, simVal); } } // if } // while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); /* * first we have to sort the vector according to the rendering ordering * (which is the x value). REALLY??? After hours of searching no better * solution found! please help! */ Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label "Sim Volumes [veh/h]", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); // regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); // outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } }); dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } }); dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); plot.getRangeAxis().setRange(1.0, 19000.0); plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:org.matsim.pt.counts.obsolete.PtCountsSimRealPerHourGraph.java
/** * @param hour// ww w. j a v a2 s.co m * A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 * a.m. ... */ @Override @Deprecated // use standard counts package public JFreeChart createChart(final int hour) { this.hour = hour; XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<String> tooltips = new ArrayList<String>(); List<Comp> comps = new Vector<Comp>(); Iterator<CountSimComparison> l_it = this.ccl_.iterator(); // int elementCounter=0; while (l_it.hasNext()) { CountSimComparison cc = l_it.next(); /* * values with simVal==0.0 or countVal==0.0 are drawn on the x==1 * or/and y==1-line Such values are the result of a poor simulation * run, but they can also represent a valid result (closing summer * road during winter time) */ if (cc.getHour() == hour) { // elementCounter++; double realVal = 1.0; double simVal = 1.0; if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) { realVal = cc.getCountValue(); simVal = cc.getSimulationValue(); series.add(realVal, simVal); comps.add(new Comp(realVal, "link" + cc.getId() + ".html", "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal)); } else { realVal = Math.max(1.0, cc.getCountValue()); simVal = Math.max(1.0, cc.getSimulationValue()); series_outliers.add(realVal, simVal); } } // if } // while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); /* * first we have to sort the vector according to the rendering ordering * (which is the x value). REALLY??? After hours of searching no better * solution found! please help! */ Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label "Sim Volumes [veh/h]", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); // regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); // outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } }); dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } }); dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); plot.getRangeAxis().setRange(1.0, 19000.0); plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private void prepareWaypontOnChart(XYPlot xyplot, Waypoint waypoint) { Vector positions = waypoint.getPositionsOnTrack(); for (int i = 0; i < positions.size(); i++) { double position = ((Double) positions.get(i)).doubleValue(); double elevation = waypoint.getElevation(); if (position > 0 && waypoint.isVisible()) { String waypointLabel; if (TrackProfilerAppContext.getInstance().isWaypointLabelFromTitle()) { waypointLabel = waypoint.getTitle(); } else { waypointLabel = waypoint.getDescription(); }//w w w. j ava 2 s .c om double arrowAngle = Math.PI * 1.5; if (waypoint.getArrowLength() < 0) { arrowAngle += Math.PI; } XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(waypointLabel, position, elevation, arrowAngle); xypointerannotation.setTipRadius(3.0D); xypointerannotation.setBaseRadius(Math.abs(waypoint.getArrowLength())); xypointerannotation.setFont(GUIConstants.SANS_SERIF_11); xypointerannotation.setPaint(Color.blue); xypointerannotation.setTextAnchor(TextAnchor.BASELINE_CENTER); xyplot.addAnnotation(xypointerannotation); ValueMarker valuemarker = new ValueMarker(position); valuemarker.setLabelOffsetType(LengthAdjustmentType.NO_CHANGE); valuemarker.setStroke(new BasicStroke(1.0F)); // TODO: u postavke da li ispisivati ovdje if (false) { valuemarker.setLabel(waypoint.getTitle()); } valuemarker.setLabelFont(GUIConstants.SANS_SERIF_11); if (waypoint instanceof TrackExtreeme) { valuemarker.setPaint(Color.blue); } else { valuemarker.setPaint(new Color(220, 220, 220)); } valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); // xyplot.addRangeMarker(valuemarker); xyplot.addDomainMarker(valuemarker); } } }
From source file:ui.Graph.java
/** * Creates a chart.//from w w w. ja v a 2 s . c om * * @param dataset * the data for the chart. * * @return a chart. */ private JFreeChart createChart(ArrayList<Setpoint> setpoints, ArrayList<Setpoint> traj) { trajectory = traj; XYSeries posSeries = new XYSeries("Position"); XYSeries trajSeries = new XYSeries("Trajectory"); XYSeries velSeries = new XYSeries("Velocity"); for (int i = 0; i < setpoints.size(); i++) { Setpoint p = setpoints.get(i); posSeries.add(p.time, p.position); velSeries.add(p.time, p.velocity); } for (int i = 0; i < trajectory.size(); i++) { Setpoint p = trajectory.get(i); trajSeries.add(p.time, p.position); } XYSeriesCollection posDataset = new XYSeriesCollection(); XYSeriesCollection trajDataset = new XYSeriesCollection(); XYSeriesCollection velDataset = new XYSeriesCollection(); posDataset.addSeries(posSeries); velDataset.addSeries(velSeries); trajDataset.addSeries(trajSeries); // create the chart... final JFreeChart chart = ChartFactory.createScatterPlot("System output", // chart title "X", // x axis label "Y", // y axis label posDataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // 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.setDataset(0, posDataset); plot.setDataset(1, trajDataset); plot.setDataset(2, velDataset); plot.setBackgroundPaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer posRenderer = new XYLineAndShapeRenderer(); // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f, // 1.0f)); posRenderer.setSeriesPaint(0, Color.BLUE); posRenderer.setSeriesLinesVisible(0, true); posRenderer.setSeriesShapesVisible(0, false); XYStepRenderer trajRenderer = new XYStepRenderer(); trajRenderer.setSeriesPaint(1, Color.RED); trajRenderer.setSeriesStroke(1, new BasicStroke(10)); trajRenderer.setSeriesLinesVisible(1, true); trajRenderer.setSeriesShapesVisible(1, false); XYLineAndShapeRenderer velRenderer = new XYLineAndShapeRenderer(); velRenderer.setSeriesPaint(0, Color.MAGENTA); velRenderer.setSeriesLinesVisible(0, true); velRenderer.setSeriesShapesVisible(0, false); // renderer.setSeriesStroke(1, new BasicStroke(0.01f)); plot.setRenderer(0, posRenderer); plot.setRenderer(1, trajRenderer); plot.setRenderer(2, velRenderer); for (Setpoint s : trajectory) { Marker marker = new ValueMarker(s.time); marker.setPaint(Color.DARK_GRAY); marker.setLabel(Float.toString((float) s.position)); marker.setLabelAnchor(RectangleAnchor.TOP_LEFT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(marker); } XYTextAnnotation p = new XYTextAnnotation("kP = " + gains.kP, plot.getDomainAxis().getUpperBound() * 0.125, plot.getRangeAxis().getUpperBound() * .75); p.setFont(new Font("Dialog", Font.PLAIN, 12)); plot.addAnnotation(p); XYTextAnnotation i = new XYTextAnnotation("kI = " + gains.kI, plot.getDomainAxis().getUpperBound() * 0.125, plot.getRangeAxis().getUpperBound() * .7); i.setFont(new Font("Dialog", Font.PLAIN, 12)); plot.addAnnotation(i); XYTextAnnotation d = new XYTextAnnotation("kD = " + gains.kD, plot.getDomainAxis().getUpperBound() * 0.125, plot.getRangeAxis().getUpperBound() * .65); d.setFont(new Font("Dialog", Font.PLAIN, 12)); plot.addAnnotation(d); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:probe.com.view.core.chart4j.VennDiagramPanel.java
/** * Update the plot.//from ww w . j a v a 2 s .com */ public void updatePlot() { // plotPanel.removeAll(); tooltipToDatasetMap = new HashMap<String, String>(); DefaultXYZDataset xyzDataset = new DefaultXYZDataset(); chart = ChartFactory.createBubbleChart(null, "X", "Y", xyzDataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot(); if (currentVennDiagramType == VennDiagramType.ONE_WAY) { plot.getRangeAxis().setRange(0.86, 1.24); plot.getDomainAxis().setRange(0.85, 1.25); } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) { plot.getRangeAxis().setRange(0.86, 1.24); plot.getDomainAxis().setRange(0.85, 1.25); } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) { plot.getRangeAxis().setRange(0.86, 1.24); plot.getDomainAxis().setRange(0.85, 1.25); } else { plot.getRangeAxis().setRange(-0.04, 0.6); plot.getDomainAxis().setRange(-0.08, 0.7); } plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); double radius = 0.1; Ellipse2D ellipse = new Ellipse2D.Double(1 - radius, 1 - radius, radius + radius, radius + radius); XYShapeAnnotation xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150), datasetAColor); // @TODO: make it possible set the line color and width? plot.addAnnotation(xyShapeAnnotation); if (currentVennDiagramType == VennDiagramType.TWO_WAY || currentVennDiagramType == VennDiagramType.THREE_WAY) { ellipse = new Ellipse2D.Double(1 - radius + 0.1, 1 - radius, radius + radius, radius + radius); xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150), datasetBColor); plot.addAnnotation(xyShapeAnnotation); } if (currentVennDiagramType == VennDiagramType.THREE_WAY) { ellipse = new Ellipse2D.Double(1 - radius + 0.05, 1 - radius + 0.1, radius + radius, radius + radius); xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150), datasetCColor); plot.addAnnotation(xyShapeAnnotation); } XYTextAnnotation anotation; if (currentVennDiagramType == VennDiagramType.ONE_WAY) { anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 1.0, 1.0); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(), legendDatasetAThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) { anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 1.0); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 1.0); anotation.setToolTipText(groupNames.get("b")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "b"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 1.0); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ab"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(), legendDatasetAThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(), legendDatasetBThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) { anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 0.97); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 0.97); anotation.setToolTipText(groupNames.get("b")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "b"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 0.97); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ab"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 1.05, 1.14); anotation.setToolTipText(groupNames.get("c")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "c"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.99, 1.065); anotation.setToolTipText( "<html>" + groupNames.get("a") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ac"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 1.11, 1.065); anotation .setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bc"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 1.05, 1.036); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abc"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(), legendDatasetAThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(), legendDatasetBThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCThreeWay.getX(), legendDatasetCThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } else if (currentVennDiagramType == VennDiagramType.FOUR_WAY) { XYBoxAnnotation anotation2 = new XYBoxAnnotation(0, 0, 0.2, 0.5, new BasicStroke(2), Color.LIGHT_GRAY, datasetAColor); plot.addAnnotation(anotation2); anotation2 = new XYBoxAnnotation(0.1, 0, 0.3, 0.4, new BasicStroke(2), Color.LIGHT_GRAY, datasetBColor); plot.addAnnotation(anotation2); anotation2 = new XYBoxAnnotation(0, 0.1, 0.4, 0.3, new BasicStroke(2), Color.LIGHT_GRAY, datasetCColor); plot.addAnnotation(anotation2); anotation2 = new XYBoxAnnotation(0, 0, 0.5, 0.2, new BasicStroke(2), Color.LIGHT_GRAY, datasetDColor); plot.addAnnotation(anotation2); anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.15, 0.45); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 0.15, 0.35); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ab"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 0.15, 0.25); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abc"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abcd").size(), 0.15, 0.15); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abcd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abd").size(), 0.15, 0.05); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.05, 0.25); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ac"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("acd").size(), 0.05, 0.15); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "acd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ad").size(), 0.05, 0.05); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ad"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 0.25, 0.35); anotation.setToolTipText("<html>" + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "b"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 0.25, 0.25); anotation .setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bc"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bcd").size(), 0.25, 0.15); anotation.setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bcd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bd").size(), 0.25, 0.05); anotation .setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 0.35, 0.25); anotation.setToolTipText("<html>" + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "c"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("cd").size(), 0.35, 0.15); anotation .setToolTipText("<html>" + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "cd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("d").size(), 0.45, 0.15); anotation.setToolTipText("<html>" + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "d"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAFourWay.getX(), legendDatasetAFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBFourWay.getX(), legendDatasetBFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCFourWay.getX(), legendDatasetCFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("d"), legendDatasetDFourWay.getX(), legendDatasetDFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } // set up the renderer XYBubbleRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plot.setRenderer(renderer); // make all datapoints semitransparent plot.setForegroundAlpha(0.5f); // remove space before/after the domain axis plot.getDomainAxis().setUpperMargin(0); plot.getDomainAxis().setLowerMargin(0); plot.setRangeGridlinePaint(Color.black); // hide unwanted chart details plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); chart.getPlot().setOutlineVisible(false); // set background color chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setBackgroundPaint(Color.WHITE); chartPanel = new ChartPanel(chart); // disable the pop up menu chartPanel.setPopupMenu(null); chartPanel.setBackground(Color.WHITE); // add the plot to the chart // plotPanel.add(chartPanel); // plotPanel.revalidate(); // plotPanel.repaint(); // // this.add(plotPanel); }
From source file:org.matsim.counts.algorithms.graphs.CountsSimReal24Graph.java
@Override public JFreeChart createChart(final int nbr) { XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<>(); final ArrayList<String> tooltips = new ArrayList<>(); List<Comp> comps = new Vector<>(); //-------------------- CountSimComparisonLinkFilter linkFilter = new CountSimComparisonLinkFilter(this.ccl_); final Vector<Id<Link>> linkIds = new CountSimComparisonLinkFilter(this.ccl_).getLinkIds(); Iterator<Id<Link>> id_it = linkIds.iterator(); double maxCountValue = 0.1; double maxSimValue = 0.1; // yyyy PtCountsKMLWriterTest.testPtAlightKMLCreation never touches these and then leads to an exception later // when they are zero. Don't know why. kai, sep'16 while (id_it.hasNext()) { Id<Link> id = id_it.next(); double countVal = linkFilter.getAggregatedCountValue(id); double simVal = linkFilter.getAggregatedSimValue(id); if (countVal > 100.0 && simVal > 100.0) { if (countVal > maxCountValue) maxCountValue = countVal; if (simVal > maxSimValue) maxSimValue = simVal;//from w w w . jav a 2 s . c o m series.add(countVal, simVal); comps.add(new Comp(countVal, "link" + id + ".html", "Link " + id + "; " + "Count: " + countVal + ", Sim: " + simVal)); } else { /* values with simVal<100.0 or countVal<100.0 are drawn on the x==100 or/and y==100-line */ countVal = Math.max(100.0, countVal); simVal = Math.max(100.0, simVal); series_outliers.add(countVal, simVal); if (countVal > maxCountValue) maxCountValue = countVal; if (simVal > maxSimValue) maxSimValue = simVal; } } //while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "Avg. Weekday Traffic Volumes, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes", // x axis label "Sim Volumes", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/24h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/24h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); //regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); //outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); Gbl.assertIf(maxCountValue > 0.); dataset1.addSeries("f1x", new double[][] { { 100.0, maxCountValue }, { 100.0, maxCountValue } }); dataset1.addSeries("f2x", new double[][] { { 100.0, maxCountValue }, { 200.0, 2 * maxCountValue } }); dataset1.addSeries("f05x", new double[][] { { 200.0, maxCountValue }, { 100.0, 0.5 * maxCountValue } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", maxCountValue, 2 * maxCountValue); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", maxCountValue, maxCountValue); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", maxCountValue, 0.5 * maxCountValue); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); //plot.getRangeAxis().setRange(1.0, 19000.0); //plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
/** * This chart uses the XYAnnotation as a glyph to represent * a single pca data point. Glyph shape is determined by survival time. * Survival of more than 10 months is represented by a circle. 10 months or less * is represented by a square. Component1 values are represented by X * Component2 values are represented by Y *//*from w w w.ja v a 2 s . c o m*/ protected void createGlyphsAndAddToPlot(XYPlot plot) { XYShapeAnnotation glyph; Shape glyphShape; Color glyphColor; PrincipalComponentAnalysisDataPoint pcaPoint; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { pcaPoint = (PrincipalComponentAnalysisDataPoint) i.next(); x = pcaPoint.getComponentValue(component1); y = pcaPoint.getComponentValue(component2); double survival = pcaPoint.getSurvivalInMonths(); if ((survival > 0) && (survival < 10.0)) { Rectangle2D.Double rect = new Rectangle2D.Double(); rect.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = rect; } else if ((survival > 0) && (survival >= 10.0)) { Ellipse2D.Double circle = new Ellipse2D.Double(); circle.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = circle; } else { //Rectangle2D.Double rect = new Rectangle2D.Double(); //rect.setFrameFromCenter(x,y, x+2,y+2); GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + 3.0f, yf - 3.0f); gp.lineTo(xf - 3.0f, yf - 3.0f); gp.closePath(); glyphShape = gp; } glyphColor = getColorForDataPoint(pcaPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = ""; if (pcaPoint.getSurvivalInMonths() <= 0.0) { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName(); } else { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName() + " survivalMonths=" + nf.format(pcaPoint.getSurvivalInMonths()); } glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }