List of usage examples for org.jfree.chart.plot XYPlot setDomainCrosshairVisible
public void setDomainCrosshairVisible(boolean flag)
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();//from w w w.j a v a 2 s .co m 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:org.encog.workbench.tabs.visualize.scatter.ScatterPlotTab.java
private JPanel createPanel(int xIndex, int yIndex, boolean legend) { XYDataset dataset = new ScatterXY(file, xIndex, yIndex); JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, dataset, PlotOrientation.VERTICAL, legend, true, false);/*from w w w . j a va2 s. c om*/ XYPlot plot = (XYPlot) chart.getPlot(); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotWidth(4); renderer.setDotHeight(4); if (this.file.isRegression()) { int per = 255 / 10; int r = 0; int b = 255; for (int i = 0; i < file.getSeriesCount(); i++) { renderer.setSeriesPaint(i, new Color(r, 0, b)); r += per; b -= per; } } else { for (int i = 0; i < file.getSeriesCount(); i++) { renderer.setSeriesPaint(i, COLORS[i % COLORS.length]); } } plot.setRenderer(renderer); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); plot.getRangeAxis().setInverted(false); ChartPanel result = new ChartPanel(chart); result.setBorder(BorderFactory.createLineBorder(Color.black)); // we need one to draw the legend off of if (this.samplePlot == null) this.samplePlot = plot; //chart.removeLegend(); return result; }
From source file:org.eumetsat.metop.visat.SounderInfoView.java
protected void configureSpectrumPlot(XYPlot plot) { plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairVisible(false); plot.setNoDataMessage(NO_IFOV_SELECTED); }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.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();/*from ww w . j a v a 2 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 <= 25.0) { tickUnit = 5.0; } else if (maxAbsVal <= 50.0) { tickUnit = 10.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:org.eumetsat.metop.visat.IasiInfoView.java
private void configureSpectrumPlot(XYPlot plot) { plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairVisible(false); plot.setNoDataMessage(NO_IFOV_SELECTED); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYDataset dataset = (XYDataset) datasets.getDatasets().get("1"); final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend, false, false);//from w w w .ja v a2 s .co m sparkLineGraph.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); sparkLineGraph.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); sparkLineGraph.addSubtitle(subTitle); } sparkLineGraph.setBorderVisible(false); sparkLineGraph.setBorderPaint(Color.BLACK); XYPlot plot = sparkLineGraph.getXYPlot(); plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(color); // calculate the last marker color Paint colorLast = getLastPointColor(); // Calculate average, minimum and maximum to draw plot borders. boolean isFirst = true; double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; int count = 0; for (int i = 0; i < timeSeries.getItemCount(); i++) { if (timeSeries.getValue(i) != null) { count++; if (isFirst) { min = timeSeries.getValue(i).doubleValue(); max = timeSeries.getValue(i).doubleValue(); isFirst = false; } double n = timeSeries.getValue(i).doubleValue(); //calculate avg, min, max avg += n; if (n < min) min = n; if (n > max) max = n; } } // average avg = avg / (double) count; // calculate min and max between thresholds! boolean isFirst2 = true; double lb = 0, ub = 0; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); if (isFirst2 == true) { ub = thres.doubleValue(); lb = thres.doubleValue(); isFirst2 = false; } if (thres.doubleValue() > ub) ub = thres.doubleValue(); if (thres.doubleValue() < lb) lb = thres.doubleValue(); } plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2)); addMarker(1, avg, Color.GRAY, 0.8f, plot); //addAvaregeSeries(series, plot); addPointSeries(timeSeries, plot); int num = 3; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); TargetThreshold targThres = thresholds.get(thres); Color color = Color.WHITE; if (targThres != null && targThres.getColor() != null) { color = targThres.getColor(); } if (targThres.isVisible()) { addMarker(num++, thres.doubleValue(), color, 0.5f, plot); } } ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin(0.2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); plot.getRenderer().setSeriesPaint(0, Color.BLACK); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { TimeSeriesDataItem tsdi = timeSeries.getDataItem(item); if (tsdi == null) return false; Month period = (Month) tsdi.getPeriod(); int currMonth = period.getMonth(); int currYear = period.getYearValue(); int lastMonthFilled = lastMonth.getMonth(); int lastYearFilled = lastMonth.getYearValue(); boolean isLast = false; if (currYear == lastYearFilled && currMonth == lastMonthFilled) { isLast = true; } return isLast; } }; renderer.setSeriesPaint(0, Color.decode("0x000000")); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(colorLast); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0)); if (wlt_mode.doubleValue() == 0) { renderer.setBaseItemLabelsVisible(Boolean.FALSE, true); } else { renderer.setBaseItemLabelsVisible(Boolean.TRUE, true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"), new DecimalFormat("0.###")) { public String generateLabel(CategoryDataset dataset, int row, int column) { if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0) return ""; String columnKey = (String) dataset.getColumnKey(column); int separator = columnKey.indexOf('-'); String month = columnKey.substring(0, separator); String year = columnKey.substring(separator + 1); int monthNum = Integer.parseInt(month); if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) { if (wlt_mode.doubleValue() == 2 && column % 2 == 0) return ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, monthNum - 1); SimpleDateFormat dataFormat = new SimpleDateFormat("MMM"); return dataFormat.format(calendar.getTime()); } else return "" + monthNum; } }); } if (wlt_mode.doubleValue() == 3) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2)); } else if (wlt_mode.doubleValue() == 4) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4)); } if (legend == true) { LegendItemCollection collection = createThresholdLegend(plot); LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage); collection.add(item); plot.setFixedLegendItems(collection); } plot.setRenderer(0, renderer); logger.debug("OUT"); return sparkLineGraph; }
From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java
/** * Creates a chart./*w w w . ja va 2 s. c o m*/ * * @param dataset a dataset. * @param clusters * * @return A chart. */ // private JFreeChart createChart(final XYDataset dataset, ArrayList<Cluster_DBScan> clusters) { // // final JFreeChart chart = ChartFactory.createTimeSeriesChart( // "Sensors", // "Time", "Erlang", // dataset, // false, //t // true, //t // false //f // ); // // ChartUtilities.applyCurrentTheme(chart); // // //chart.setBackgroundPaint(Color.white); // //// final StandardLegend sl = (StandardLegend) chart.getLegend(); //// sl.setDisplaySeriesShapes(true); // // final XYPlot plot = chart.getXYPlot(); // plot.setBackgroundPaint(Color.WHITE); // plot.setDomainGridlinePaint(Color.white); // plot.setRangeGridlinePaint(Color.white); //// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); // plot.setDomainCrosshairVisible(true); // plot.setRangeCrosshairVisible(true); // // final XYItemRenderer renderer = plot.getRenderer(); // // if (renderer instanceof StandardXYItemRenderer) // { // final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; // //rr.setPlotShapes(true); // rr.setShapesFilled(true); // rr.setItemLabelsVisible(true); // } // // int temp_count = 0; // // //for (int i = 0; i < clusters.size(); i++) // for (int i = 0; (i < 11) && (i < clusters.size()); i++) // { // Cluster_DBScan current_cluster = clusters.get(i); // ArrayList<Day_24d> member_time_series = current_cluster.getMembership(); // // for (int j = 0; j < member_time_series.size(); j++) // { // renderer.setSeriesPaint(j+temp_count, getColor(i)); // } // temp_count = temp_count + member_time_series.size(); // } // // final DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); // // final ValueAxis axis_y = plot.getRangeAxis(); // axis_y.setRange(0, 100); // // return chart; // // } private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset_centroids, ArrayList<Cluster_KMeans> clusters) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sensors", "Time", "Erlang", dataset, false, //t true, //t false //f ); ChartUtilities.applyCurrentTheme(chart); //chart.setBackgroundPaint(Color.white); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; //rr.setPlotShapes(true); rr.setShapesFilled(true); rr.setItemLabelsVisible(true); } int temp_count = 0; //for (int i = 0; i < clusters.size(); i++) for (int i = 0; (i < 11) && (i < clusters.size()); i++) { Cluster_KMeans current_cluster = clusters.get(i); ArrayList<Day_24d> member_time_series = current_cluster.getMembership(); for (int j = 0; j < member_time_series.size(); j++) { renderer.setSeriesPaint(j + temp_count, getColor(i)); } temp_count = temp_count + member_time_series.size(); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); //final ValueAxis axis_y = plot.getRangeAxis(); //axis_y.setRange(0, 20); plot.setDataset(1, dataset_centroids); plot.setRenderer(1, new StandardXYItemRenderer()); for (int i = 0; (i < clusters.size()); i++) { //plot.getRenderer(1).setSeriesPaint(i, getColor(i)); plot.getRenderer(1).setSeriesPaint(i, Color.BLACK); plot.getRenderer(1).setSeriesStroke(i, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); } plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);//from w w w .ja v a 2 s. c o m plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // 2. Setup Scatter plot // Create the scatter data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot plotRenderer.setBaseToolTipGenerator(plotToolTip); // Set the scatter data, renderer, and axis into plot plot.setDataset(0, getScatterPlotData(features, xField, yField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); // Degree XYSeries degree = new XYSeries("Deegree"); //$NON-NLS-1$ degree.add(xPlotAxis.getRange().getLowerBound(), yPlotAxis.getRange().getLowerBound()); degree.add(xPlotAxis.getRange().getUpperBound(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(degree); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY))); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
protected 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(); if (!this.colorBy.equals(PCAcolorByType.NONE)) { buildLegend();//from www . j av a 2 s. co m } 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(150.0, maxAbsVal); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setRange(-maxAbsVal, maxAbsVal); rangeAxis.setRange(-maxAbsVal, maxAbsVal); domainAxis.setTickUnit(new NumberTickUnit(25.0)); rangeAxis.setTickUnit(new NumberTickUnit(25.0)); createGlyphsAndAddToPlot(plot); // 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:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override public void initChart(final IScope scope, final String chartname) { super.initChart(scope, chartname); final XYPlot pp = (XYPlot) chart.getPlot(); pp.setDomainGridlinePaint(axesColor); pp.setRangeGridlinePaint(axesColor); pp.setDomainCrosshairPaint(axesColor); pp.setRangeCrosshairPaint(axesColor); pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); pp.setDomainCrosshairVisible(false); pp.setRangeCrosshairVisible(false);// www . java 2s . co m pp.setRangeGridlinesVisible(false); pp.setDomainGridlinesVisible(false); pp.getDomainAxis().setAxisLinePaint(axesColor); pp.getDomainAxis().setTickLabelFont(getTickFont()); pp.getDomainAxis().setLabelFont(getLabelFont()); if (textColor != null) { pp.getDomainAxis().setLabelPaint(textColor); pp.getDomainAxis().setTickLabelPaint(textColor); } if (xtickunit > 0) { ((NumberAxis) pp.getDomainAxis()).setTickUnit(new NumberTickUnit(xtickunit)); } pp.getRangeAxis().setAxisLinePaint(axesColor); pp.getRangeAxis().setLabelFont(getLabelFont()); pp.getRangeAxis().setTickLabelFont(getTickFont()); if (textColor != null) { pp.getRangeAxis().setLabelPaint(textColor); pp.getRangeAxis().setTickLabelPaint(textColor); } if (ytickunit > 0) { ((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit)); } // resetAutorange(scope); if (xlabel != null && !xlabel.isEmpty()) { pp.getDomainAxis().setLabel(xlabel); } if (ylabel != null && !ylabel.isEmpty()) { pp.getRangeAxis().setLabel(ylabel); } }