List of usage examples for org.jfree.chart.plot XYPlot setRangeCrosshairVisible
public void setRangeCrosshairVisible(boolean flag)
From source file:visualizer.datamining.dataanalysis.CreateLineGraph.java
private JFreeChart createChart(XYDataset xydataset, String title, String xtitle, String ytitle) { JFreeChart chart = ChartFactory.createXYLineChart(title, xtitle, ytitle, xydataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); xyplot.setDomainGridlinePaint(Color.BLACK); xyplot.setRangeGridlinePaint(Color.BLACK); xyplot.setOutlinePaint(Color.BLACK); xyplot.setOutlineStroke(new BasicStroke(1.0f)); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); xyplot.setDrawingSupplier(new DefaultDrawingSupplier( new Paint[] { Color.RED, Color.BLUE, Color.GREEN, Color.MAGENTA, Color.CYAN, Color.ORANGE, Color.BLACK, Color.DARK_GRAY, Color.GRAY, Color.LIGHT_GRAY, Color.YELLOW }, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); xylineandshaperenderer.setDrawOutlines(true); return chart; }
From source file:org.tolven.web.ChartAction.java
/** * Create Growth Chart/*from ww w . j a v a 2s. c o m*/ * * @author Suja * added on 02/01/2011 * @param type - 1: Height & 2: Weight * @return */ public JFreeChart createChart(int type) { long patientId = Long.parseLong(getRequestParameter("element").toString().split(":")[1].split("-")[1]); MenuData patMD = getMenuLocal().findMenuDataItem(patientId); int age = 0; int gender = 1; Date dob = null; if (patMD != null) { DateFormat df = new SimpleDateFormat("yyyy"); dob = patMD.getDate01(); Date cur = new Date(); age = Integer.parseInt(df.format(cur)) - Integer.parseInt(df.format(dob)); if (patMD.getString04().equals("Male")) gender = 1; else gender = 2; } // create dataset XYDataset dataset = createDataset(type, gender, age, dob); String title = ""; if (type == 1 && age < 3) title = "Height birth to 36 Months Old " + (gender == 1 ? "Male" : "Female"); else if (type == 1 && age >= 3) title = "Height 2-20 Year Old " + (gender == 1 ? "Male" : "Female"); else if (type == 2 && age < 3) title = "Weight birth to 36 Months Old " + (gender == 1 ? "Male" : "Female"); else if (type == 2 && age >= 3) title = "Weight 2-20 Year Old " + (gender == 1 ? "Male" : "Female"); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "X-Value", // x-axis label "Y-Value", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.lightGray); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 1; i < 10; i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); plot.setDomainAxis(new NumberAxis("Age (Months)")); plot.setRangeAxis(new NumberAxis((type == 1 ? "Height (Centimeters)" : "Weight (Kilograms)"))); return chart; }
From source file:my.electrochem.ElectrochemUI.java
private ChartPanel createChartPanel() { //creates a line chart object //returns the chart panel String chartTitle = "i-E curve"; String xAxisLabel = "E (V)"; String yAxisLabel = "i (A)"; dataset1 = createEmptyDataset();/*from w w w . j av a2 s .c o m*/ JFreeChart chart = ChartFactory.createScatterPlot(chartTitle, xAxisLabel, yAxisLabel, dataset1); XYPlot plot = chart.getXYPlot(); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairLockedOnData(false); plot.setRangeCrosshairLockedOnData(false); /*chart.addProgressListener(new ChartProgressListener() { @Override public void chartProgress(ChartProgressEvent cpe) { if (cpe.getType() == ChartProgressEvent.DRAWING_FINISHED) { //System.out.println("Click event!!"); XYPlot xyPlot2 = cpe.getChart().getXYPlot(); System.out.println("drawing finished"); System.out.println("Xreal:"+xyPlot2.getDomainCrosshairValue() +"Yreal:"+xyPlot2.getRangeCrosshairValue()); if (click) { System.out.println("click true"); if (x1 == -423.0) { x1 = 0.0; y1 = 0.0; } if (x1 == 0.0 && y1 == 0.0) { System.out.println("print 0,0"); click = true; x1 = xyPlot2.getDomainCrosshairValue(); y1 = xyPlot2.getRangeCrosshairValue(); //xyPlot2.clearAnnotations(); } else { xyPlot2.clearAnnotations(); System.out.println("true-false"); click = false; x1 = xyPlot2.getDomainCrosshairValue(); y1 = xyPlot2.getRangeCrosshairValue(); } } else { System.out.println("click false"); x2 = xyPlot2.getDomainCrosshairValue(); y2 = xyPlot2.getRangeCrosshairValue(); createLineAnn(xyPlot2, x1, y1, x2, y2); click = true; } } } });*/ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // sets paint color for each series //renderer.setSeriesPaint(0, Color.RED); // sets thickness for series (using strokes) //renderer.setSeriesStroke(0, new BasicStroke(5.0f)); renderer.setBaseLinesVisible(true); //renderer.setSeriesLinesVisible(0, true); //renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(false); //srenderer.setDrawSeriesLineAsPath(false); plot.setOutlinePaint(Color.BLUE); plot.setOutlineStroke(new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.DARK_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRenderer(renderer); return new ChartPanel(chart); }
From source file:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java
/** * Creates a chart./*w w w . ja va 2 s .c o m*/ * * @param dataset1 a dataset. * * @return A chart. */ private JFreeChart createChart(XYDataset dataset, long lastentry) { JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title "time", // x-axis label "temperature", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis1 = new NumberAxis(getAxisName()); axis1.setAutoRangeIncludesZero(isIncludeZero()); plot.setRangeAxis(0, axis1); plot.setDataset(0, dataset); plot.mapDatasetToRangeAxis(1, 0); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); //TODO: SHADOWS OFF final StandardXYItemRenderer r1 = new StandardXYItemRenderer(); plot.setRenderer(0, r1); r1.setSeriesPaint(0, Color.BLUE); r1.setSeriesPaint(1, Color.RED); r1.setSeriesPaint(2, Color.GREEN); //plot.setDomainAxis(new NumberAxis("time")); plot.setDomainAxis(new DateAxis()); plot.getDomainAxis().setAutoRange(false); long begin = getRangeBegin(lastentry); long end = getRangeEnd(lastentry); plot.getDomainAxis().setRange(begin, end); return chart; }
From source file:gov.nih.nci.cma.web.graphing.CMAPrincipalComponentAnalysisPlot.java
private void createChart() { String xLabel = component1.toString(); String yLabel = component2.toString(); pcaChart = ChartFactory.createScatterPlot("Principal Component Analysis", xLabel, yLabel, null, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) pcaChart.getPlot(); buildLegend();//ww w . ja v a2 s . c om plot.setNoDataMessage(null); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setUseOutlinePaint(true); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairVisible(false); // XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5)); // // plot.addAnnotation(annotation); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); //should determine axis range using datapoints. DataRange component1Range = getDataRange(dataPoints, PCAcomponent.PC1); DataRange component2Range = getDataRange(dataPoints, PCAcomponent.PC2); DataRange component3Range = getDataRange(dataPoints, PCAcomponent.PC3); Double pc1AbsMax = Math.max(Math.abs(component1Range.getMaxRange()), Math.abs(component1Range.getMinRange())); Double pc2AbsMax = Math.max(Math.abs(component2Range.getMaxRange()), Math.abs(component2Range.getMinRange())); Double pc3AbsMax = Math.max(Math.abs(component3Range.getMaxRange()), Math.abs(component3Range.getMinRange())); Double maxAbsVal = Math.max(pc1AbsMax, pc2AbsMax); maxAbsVal = Math.max(maxAbsVal, pc3AbsMax); //maxAbsVal = Math.max(100.0, maxAbsVal); domainAxis.setAutoRangeIncludesZero(false); double tickUnit = 25.0; if (maxAbsVal <= 50.0 && maxAbsVal >= 25.0) { tickUnit = 10.0; //5.0; } else if (maxAbsVal <= 25.0) { tickUnit = 5.0; } domainAxis.setTickUnit(new NumberTickUnit(tickUnit)); rangeAxis.setTickUnit(new NumberTickUnit(tickUnit)); double glyphScaleFactor = (maxAbsVal * 2.0) / 600.0; //assuming 600 pixels for the graph double adjAbsVal = Math.ceil(maxAbsVal + (glyphScaleFactor * 8.0)); //domainAxis.setRange(-maxAbsVal, maxAbsVal); domainAxis.setRange(-adjAbsVal, adjAbsVal); //rangeAxis.setRange(-maxAbsVal, maxAbsVal); rangeAxis.setRange(-adjAbsVal, adjAbsVal); createGlyphsAndAddToPlot(plot); //, glyphScaleFactor); // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green); //try and match the UI e9e9e9 Paint p = new Color(233, 233, 233); pcaChart.setBackgroundPaint(p); }
From source file:mekhq.gui.FinancesTab.java
private JFreeChart createAmountChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title resourceMap.getString("graphDate.text"), // x-axis label resourceMap.getString("graphCBills.text"), // y-axis label dataset);/*from ww w .j a v a 2s .com*/ chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setDefaultShapesVisible(true); renderer.setDefaultShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); chart.removeLegend(); return chart; }
From source file:visualizer.datamining.dataanalysis.NeighborhoodHit.java
private JFreeChart createChart(XYDataset xydataset) { JFreeChart chart = ChartFactory.createXYLineChart("Neighborhood Hit", "Number Neighbors", "Precision", xydataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); xyplot.setDomainGridlinePaint(Color.BLACK); xyplot.setRangeGridlinePaint(Color.BLACK); xyplot.setOutlinePaint(Color.BLACK); xyplot.setOutlineStroke(new BasicStroke(1.0f)); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); xyplot.setDrawingSupplier(new DefaultDrawingSupplier( new Paint[] { Color.RED, Color.BLUE, Color.GREEN, Color.MAGENTA, Color.CYAN, Color.ORANGE, Color.BLACK, Color.DARK_GRAY, Color.GRAY, Color.LIGHT_GRAY, Color.YELLOW }, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); xylineandshaperenderer.setDrawOutlines(true); return chart; }
From source file:org.limy.eclipse.qalab.task.DistanceGraphTask.java
/** * @param dataset /*from w ww .j ava2 s.c om*/ * @throws IOException * */ private void drawGraph(XYDataset dataset) throws IOException { JFreeChart chart = ChartFactory.createScatterPlot("Distance from the Main Sequence", "Instability", "Abstractness", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = chart.getXYPlot(); plot.getRenderer().addAnnotation( new XYLineAnnotation(-0.1, 1.1, 1.1, -0.1, new BasicStroke(2), new Color(50, 220, 50)), Layer.BACKGROUND); plot.getRenderer().setShape(new Ellipse2D.Double(-4, -4, 8, 8)); plot.getRenderer().setPaint(new Color(0xec, 0x76, 0x37)); plot.getDomainAxis().setRangeWithMargins(0, 1); plot.getRangeAxis().setRangeWithMargins(0, 1); chart.getTitle().setPaint(Color.BLUE); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairPaint(Color.GRAY); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairPaint(Color.GRAY); LimyGraphUtils.writeImagePng(chart, out, 400, 380); }
From source file:mil.tatrc.physiology.biogears.verification.ScenarioPlotTool.java
public void formatXYPlot(JFreeChart chart, Paint bgColor) { XYPlot plot = (XYPlot) chart.getPlot(); //For Scientific notation NumberFormat formatter = new DecimalFormat("0.######E0"); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setNumberFormatOverride(formatter); //White background outside of plottable area chart.setBackgroundPaint(bgColor);//from w ww.j av a 2 s .c o m plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); //Changing font sizes so they are readable. plot.getDomainAxis().setLabelFont(largeFont); plot.getRangeAxis().setLabelFont(largeFont); plot.getDomainAxis().setTickLabelFont(smallFont); plot.getRangeAxis().setTickLabelFont(smallFont); plot.getDomainAxis().setLabelPaint(bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis().setLabelPaint(bgColor == Color.red ? Color.white : Color.black); plot.getDomainAxis().setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis().setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black); chart.getLegend().setItemFont(smallFont); chart.getTitle().setFont(largeFont); chart.getTitle().setPaint(bgColor == Color.red ? Color.white : Color.black); }
From source file:fr.amap.lidar.amapvox.chart.VoxelsToChart.java
public JFreeChart createChart(String title, XYSeriesCollection dataset, String xAxisLabel, String yAxisLabel) { JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true);/*from w w w . jav a 2 s.c om*/ plot.setRangePannable(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); LegendTitle subtitle = (LegendTitle) chart.getSubtitles().get(0); subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); Ellipse2D.Float shape = new Ellipse2D.Float(-2.5f, -2.5f, 5.0f, 5.0f); for (int i = 0; i < voxelFiles.length; i++) { renderer.setSeriesShape(i, shape); renderer.setSeriesPaint(i, voxelFiles[i].getSeriesParameters().getColor()); renderer.setLegendTextPaint(i, voxelFiles[i].getSeriesParameters().getColor()); } } return chart; }