List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:GUI.PlotCreator.java
private ChartPanel createSeaCurrentDirectionByTimePanel() { JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "Time(Hours)", "Sea Current Direction", createSeaCurrentDirectionByTime(), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); //XYItemRenderer renderer = xyPlot.getRenderer(); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setTickUnit(new NumberTickUnit(1.0)); domain.setVerticalTickLabels(true);/* w ww. jav a 2s . c o m*/ return new ChartPanel(jfreechart); }
From source file:io.github.mzmine.util.jfreechart.IntelligentItemLabelGenerator.java
/** * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset, * int, int)//from ww w . j a v a2 s . c om */ public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) { XYPlot plot = chartNode.getChart().getXYPlot(); // X and Y values of the current data point final double currentXValue = currentDataset.getXValue(currentSeries, currentItem); final double currentYValue = currentDataset.getYValue(currentSeries, currentItem); // Calculate X axis span of 1 screen pixel final double xLength = plot.getDomainAxis().getRange().getLength(); final double pixelX = xLength / chartNode.getWidth(); // Calculate the distance from the current point where labels might // overlap final double dangerZoneX = (reservedPixels / 2) * pixelX; // Range on X axis that we're going to check for higher data points. If // a higher data point is found, we don't place a label on this one. final Range<Double> dangerZoneRange = Range.closed(currentXValue - dangerZoneX, currentXValue + dangerZoneX); // Iterate through data sets for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) { XYDataset dataset = plot.getDataset(datasetIndex); // Some data sets could have been removed if (dataset == null) continue; final int seriesCount = dataset.getSeriesCount(); // Iterate through series for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { final int itemCount = dataset.getItemCount(seriesIndex); // Find the index of a data point that is closest to // currentXValue int closestValueIndex; if (dataset == currentDataset && seriesIndex == currentSeries) { closestValueIndex = currentItem; } else { closestValueIndex = findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1); } // Search to the left of the closest data point for (int i = closestValueIndex; (i >= 0) && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) { if (dataset.getYValue(seriesIndex, i) > currentYValue) return null; // In the case there are equal values, only place the label // on the leftmost value if (dataset.getYValue(seriesIndex, i) == currentYValue && (dataset.getXValue(seriesIndex, i) < currentXValue)) return null; } // Search to the right of the closest data point for (int i = closestValueIndex + 1; (i < itemCount) && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) { if (dataset.getYValue(seriesIndex, i) > currentYValue) return null; } } } // If no higher data point was found, create the label String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem); return label; }
From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java
/** * Creates a line chart.// ww w .j a v a 2 s . co m * * @param title * @param categoryAxisLabel * (X-Axis label) * @param valueAxisLabel * (Y-Axis label) * @param dataset * @param includeZero * True when zero shall be included to the axis range. * @return JfreeChart instance. */ public JFreeChart createXYLineSplineChart(String title, String categoryAxisLabel, String valueAxisLabel, XYDataset dataset, boolean includeZero, boolean drawShapes) { JFreeChart chart = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset, this.orientation, this.drawLegend, false, false); // set the background color for the chart... chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundAlpha(0.4f); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.025); domainAxis.setUpperMargin(0.025); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(includeZero); plot.setRenderer(new XYSplineRenderer(100)); XYSplineRenderer renderer = (XYSplineRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesPaint(2, Color.green); renderer.setSeriesPaint(3, Color.darkGray); renderer.setSeriesPaint(4, Color.yellow); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseShapesVisible(drawShapes); renderer.setBaseShapesFilled(true); return chart; }
From source file:ac.openmicrolabs.view.gui.OMLLoggerView.java
private JPanel createContentPane(final TimeSeriesCollection t, final String graphTitle, final double graphTimeRange, final String[] signals) { btmPanel.remove(reportButton);/*from w w w.jav a 2 s .c om*/ chanLabel = new JLabel[signals.length]; int activeSignalCount = 0; for (int i = 0; i < signals.length; i++) { chanLabel[i] = new JLabel(h.format("label", (char) ((i / PIN_COUNT) + ASCII_OFFSET) + "-0x" + String.format("%02x", (i % PIN_COUNT) + SLAVE_BITS).toUpperCase())); chanLabel[i].setHorizontalAlignment(JLabel.CENTER); if (signals[i] != null) { activeSignalCount++; } else { chanLabel[i].setEnabled(false); } } typeLabel = new JLabel[activeSignalCount]; valLabel = new JLabel[activeSignalCount]; minLabel = new JLabel[activeSignalCount]; maxLabel = new JLabel[activeSignalCount]; avgLabel = new JLabel[activeSignalCount]; int index = 0; for (int i = 0; i < signals.length; i++) { if (signals[i] != null) { typeLabel[index] = new JLabel(h.format("body", signals[i])); typeLabel[index].setHorizontalAlignment(JLabel.CENTER); index++; } } for (int i = 0; i < activeSignalCount; i++) { valLabel[i] = new JLabel(); valLabel[i].setHorizontalAlignment(JLabel.CENTER); minLabel[i] = new JLabel(); minLabel[i].setHorizontalAlignment(JLabel.CENTER); maxLabel[i] = new JLabel(); maxLabel[i].setHorizontalAlignment(JLabel.CENTER); avgLabel[i] = new JLabel(); avgLabel[i].setHorizontalAlignment(JLabel.CENTER); } // Set up main panel. JPanel mainPanel = new JPanel(); mainPanel.setLayout(null); mainPanel.setBackground(Color.white); // Create graph. snsChart = ChartFactory.createTimeSeriesChart(graphTitle, GRAPH_X_LABEL, GRAPH_Y_LABEL, t, true, true, false); final XYPlot plot = snsChart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(graphTimeRange); axis = plot.getRangeAxis(); axis.setRange(graphMinY, graphMaxY); ChartPanel snsChartPanel = new ChartPanel(snsChart); snsChartPanel.setPreferredSize(new Dimension(FRAME_WIDTH - PAD20, GRAPH_HEIGHT - PAD10)); // Set up graph panel. final JPanel graphPanel = new JPanel(); graphPanel.setSize(FRAME_WIDTH - PAD20, GRAPH_HEIGHT); graphPanel.setLocation(0, 0); graphPanel.setBackground(Color.white); graphPanel.add(snsChartPanel); // Set up results panel. final JPanel resultsPanel = createResultsPane(); // Set up scroll pane. final JScrollPane scrollPane = new JScrollPane(resultsPanel); scrollPane.setSize(FRAME_WIDTH - PAD20, FRAME_HEIGHT - BTM_HEIGHT - GRAPH_HEIGHT + PAD8); scrollPane.setLocation(PAD5, GRAPH_HEIGHT); scrollPane.setBackground(Color.white); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); // Set results panel size. resultsPanel.setPreferredSize(new Dimension(PAD40 + (signals.length * RESULTS_COL_WIDTH), FRAME_HEIGHT - BTM_HEIGHT - GRAPH_HEIGHT - PAD120)); resultsPanel.revalidate(); // Set up bottom panel. btmPanel.setLayout(null); btmPanel.setSize(FRAME_WIDTH, BTM_HEIGHT); btmPanel.setLocation(0, this.getHeight() - BTM_HEIGHT); btmPanel.setBackground(Color.white); // Instantiate bottom panel objects. footerLabel.setSize(LABEL_WIDTH, LABEL_HEIGHT); footerLabel.setLocation(LABEL_X, LABEL_Y); footerLabel.setText(""); doneButton.setIcon(new ImageIcon("img/22x22/stop.png")); doneButton.setSize(DONE_WIDTH, DONE_HEIGHT); doneButton.setLocation(FRAME_WIDTH - PAD20 - doneButton.getWidth(), PAD15); progressBar = new JProgressBar(); progressBar.setSize(FRAME_WIDTH - PAD40 - doneButton.getWidth() - footerLabel.getWidth(), PAD20); progressBar.setValue(0); progressBar.setLocation(footerLabel.getWidth() + PAD10, PAD22); // Populate bottom panel. btmPanel.add(footerLabel); btmPanel.add(progressBar); btmPanel.add(doneButton); // Populate main panel. mainPanel.add(graphPanel); mainPanel.add(scrollPane); mainPanel.add(btmPanel); return mainPanel; }
From source file:GUI.PlotCreator.java
private ChartPanel createSeaCurrentSpeedByHPanel() { JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "H", "Sea Current Speed", createSeaCurrentSpeedDataByH(), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); //XYItemRenderer renderer = xyPlot.getRenderer(); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setVerticalTickLabels(true);// w ww .ja v a 2 s . co m XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); xyPlot.setRenderer(renderer); return new ChartPanel(jfreechart); }
From source file:GUI.PlotCreator.java
private ChartPanel createSeaCurrentDirectionByHPanel() { JFreeChart jfreechart = ChartFactory.createScatterPlot("Sea Current Direction Plot", "H", "Sea Current Direction", createSeaCurrentDirectionDataByH(), PlotOrientation.VERTICAL, true, true, false);/*from w w w. j a v a 2 s . c o m*/ XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); //XYItemRenderer renderer = xyPlot.getRenderer(); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setVerticalTickLabels(true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); xyPlot.setRenderer(renderer); return new ChartPanel(jfreechart); }
From source file:GUI.PlotCreator.java
private ChartPanel createEquirectangularErrorPanel(ArrayList<double[]> dataToDisplay) { title = "Equirectangular vs Haversine - Error Plot"; JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "Distance Between Points (meters)", "Error", createEquirectangularErrorData(dataToDisplay), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); //XYItemRenderer renderer = xyPlot.getRenderer(); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setVerticalTickLabels(true);/*from www . ja v a2 s . c o m*/ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); xyPlot.setRenderer(renderer); return new ChartPanel(jfreechart); }
From source file:speedbagalg.OscopeView.java
private void startButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_startButtonActionPerformed {//GEN-HEADEREND:event_startButtonActionPerformed if (startButton.getText() == "Start") { xData.clear();/*from ww w . j a va2s. com*/ yData.clear(); zData.clear(); averageData.clear(); minStart = 0; minTime = 0; hitCountTextField.setText("0"); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(false); axis.setRange(minStart, maxDomain); theLoop = new MainLoop(fileName, this); mainThread = new Thread(theLoop); mainThread.start(); startButton.setText("Stop"); } else if (startButton.getText() == "Stop") { theLoop.stop(); startButton.setText("Resume"); } else if (startButton.getText() == "Resume") { theLoop.resume(); startButton.setText("Stop"); } }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void showSelectionPopup(Rectangle2D rectangle) { XYPlot plot = chartpanel_.getChart().getXYPlot(); Rectangle2D dataArea = chartpanel_.getScreenDataArea(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); double minX = domainAxis.java2DToValue(rectangle.getMinX(), dataArea, plot.getDomainAxisEdge()); double maxX = domainAxis.java2DToValue(rectangle.getMaxX(), dataArea, plot.getDomainAxisEdge()); Date startDate = new Date((long) minX); Date endDate = new Date((long) maxX); TsPeriod start = new TsPeriod(firstPeriod.getFrequency(), startDate); TsPeriod end = new TsPeriod(firstPeriod.getFrequency(), endDate); if (end.minus(start) == 0) { return;/*from w w w. ja v a 2s . c o m*/ } TsPeriodSelector sel = new TsPeriodSelector(); sel.between(start.firstday(), end.lastday()); List<TsData> listSeries = history_.Select(info_, startDate, endDate); List<TsData> revSeries = new ArrayList<>(); for (TsData t : listSeries) { revSeries.add(t.select(sel)); } Point pt = new Point((int) rectangle.getX(), (int) rectangle.getY()); pt.translate(3, 3); SwingUtilities.convertPointToScreen(pt, chartpanel_); popup.setLocation(pt); popup.setChartTitle(info_.toUpperCase() + " First estimations"); popup.setTsData(sRef.select(sel), revSeries); popup.setVisible(true); chartpanel_.repaint(); }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();// w ww . j av a2 s . c o m Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Rectangle2D entityBounds = entity.getBounds2D(); double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge); double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge); double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge); double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge); PlotOrientation orientation = plot.getOrientation(); //transform model to origin (0,0) in model coordinates AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(), -entityBounds.getCenterY()); //transform from origin (0,0) to model location AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(), entityBounds.getCenterY()); //transform from model scale to view scale double scaleX = viewW / entityBounds.getWidth(); double scaleY = viewH / entityBounds.getHeight(); Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}", new Object[] { scaleX, scaleY }); AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY); AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f); AffineTransform modelToView = new AffineTransform(toOrigin); modelToView.preConcatenate(flipTransform); modelToView.preConcatenate(toViewScale); modelToView.preConcatenate(toViewLocation); // // if (orientation == PlotOrientation.HORIZONTAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewY, // viewX); // } else if (orientation == PlotOrientation.VERTICAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewX, // viewY); // } FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity) .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }