List of usage examples for org.jfree.chart.axis ValueAxis setRange
public void setRange(double lower, double upper)
From source file:com.wattzap.view.graphs.SCHRGraph.java
public SCHRGraph(ArrayList<Telemetry> telemetry[]) { super();/* ww w. ja va 2 s . co m*/ this.telemetry = telemetry; final NumberAxis domainAxis = new NumberAxis("Time (h:m:s)"); domainAxis.setVerticalTickLabels(true); domainAxis.setTickLabelPaint(Color.black); domainAxis.setAutoRange(true); domainAxis.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double millis, StringBuffer toAppendTo, FieldPosition pos) { if (millis >= 3600000) { // hours, minutes and seconds return new StringBuffer( String.format("%d:%d:%d", TimeUnit.MILLISECONDS.toHours((long) millis), TimeUnit.MILLISECONDS.toMinutes( (long) millis - TimeUnit.MILLISECONDS.toHours((long) millis) * 3600000), TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES .toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } else if (millis >= 60000) { // minutes and seconds return new StringBuffer(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) millis), TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } else { return new StringBuffer(String.format("%d", TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return new StringBuffer(String.format("%s", number)); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); // create plot ... final XYItemRenderer powerRenderer = new StandardXYItemRenderer() { Stroke regularStroke = new BasicStroke(0.7f); Color color; public void setColor(Color color) { this.color = color; } @Override public Stroke getItemStroke(int row, int column) { return regularStroke; } @Override public Paint getItemPaint(int row, int column) { return orange; } }; powerRenderer.setSeriesPaint(0, orange); plot = new XYPlot(); plot.setRenderer(0, powerRenderer); plot.setRangeAxis(0, powerAxis); plot.setDomainAxis(domainAxis); // add a second dataset and renderer... final XYItemRenderer cadenceRenderer = new StandardXYItemRenderer() { Stroke regularStroke = new BasicStroke(0.7f); Color color; public void setColor(Color color) { this.color = color; } @Override public Stroke getItemStroke(int row, int column) { return regularStroke; } @Override public Paint getItemPaint(int row, int column) { return cornflower; } public Shape lookupLegendShape(int series) { return new Rectangle(15, 15); } }; final ValueAxis cadenceAxis = new NumberAxis(userPrefs.messages.getString("cDrpm")); cadenceAxis.setRange(0, 200); // arguments of new XYLineAndShapeRenderer are to activate or deactivate // the display of points or line. Set first argument to true if you want // to draw lines between the points for e.g. plot.setRenderer(1, cadenceRenderer); plot.setRangeAxis(1, cadenceAxis); plot.mapDatasetToRangeAxis(1, 1); cadenceRenderer.setSeriesPaint(0, cornflower); // add a third dataset and renderer... final XYItemRenderer hrRenderer = new StandardXYItemRenderer() { Stroke regularStroke = new BasicStroke(0.7f); Color color; public void setColor(Color color) { this.color = color; } @Override public Stroke getItemStroke(int row, int column) { return regularStroke; } @Override public Paint getItemPaint(int row, int column) { return straw; } }; // arguments of new XYLineAndShapeRenderer are to activate or deactivate // the display of points or line. Set first argument to true if you want // to draw lines between the points for e.g. final ValueAxis heartRateAxis = new NumberAxis(userPrefs.messages.getString("hrBpm")); heartRateAxis.setRange(0, 200); plot.setRenderer(2, hrRenderer); hrRenderer.setSeriesPaint(0, straw); plot.setRangeAxis(2, heartRateAxis); plot.mapDatasetToRangeAxis(2, 2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setBackgroundPaint(Color.DARK_GRAY); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.getLegend().setBackgroundPaint(Color.gray); chartPanel = new ChartPanel(chart); // TODO: maybe remember sizes set by user? this.setPreferredSize(new Dimension(1200, 500)); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setBackground(Color.gray); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); SmoothingPanel smoothingPanel = new SmoothingPanel(this); add(smoothingPanel, BorderLayout.SOUTH); //infoPanel = new InfoPanel(); //add(infoPanel, BorderLayout.NORTH); setVisible(true); }
From source file:playground.thibautd.utils.charts.ChartsAxisUnifier.java
public void applyUniformisation() { for (JFreeChart chart : charts) { Plot plot = chart.getPlot();//from ww w.j ava 2 s . c om ValueAxis xAxis = null; ValueAxis yAxis = null; if (plot instanceof XYPlot) { xAxis = unifyX ? chart.getXYPlot().getDomainAxis() : null; yAxis = unifyY ? chart.getXYPlot().getRangeAxis() : null; } else if (plot instanceof CategoryPlot) { yAxis = unifyY ? chart.getCategoryPlot().getRangeAxis() : null; } if (xAxis != null) xAxis.setRange(lowerX, upperX); if (yAxis != null) yAxis.setRange(lowerY, upperY); } }
From source file:com.bdb.weather.display.day.DayTemperaturePane.java
@Override public void finishLoadData() { if (recordHigh == null || recordLow == null) return;/*from w ww .j a v a 2s . c o m*/ ValueAxis axis = getPlot().getRangeAxis(); Range range = axis.getRange(); double lowRange = recordLow.get() < range.getLowerBound() ? recordLow.get() : range.getLowerBound(); double highRange = recordHigh.get() > range.getUpperBound() ? recordHigh.get() : range.getUpperBound(); axis.setAutoRange(false); axis.setRange(lowRange - 10.0, highRange + 10.0); }
From source file:ac.openmicrolabs.view.gui.OMLLoggerView.java
@Override public final void setViewLoggingCompleted(final double graphTimeRange) { final XYPlot plot = snsChart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true);//w w w . j a va2s. co m axis.setFixedAutoRange(graphTimeRange); axis = plot.getRangeAxis(); axis.setRange(graphMinY, graphMaxY); this.setTitle(OMLAppDetails.name()); valSideLabel.setText(h.format("label-bold", avgSideLabel.getText())); avgSideLabel.setText(""); for (int i = 0; i < avgLabel.length; i++) { valLabel[i].setText(h.format("label-bold", h.get("body").unformat(avgLabel[i].getText()))); avgLabel[i].setText(""); } reportButton.setSize(doneButton.getSize()); reportButton.setIcon(new ImageIcon("img/22x22/save.png")); reportButton.setLocation(doneButton.getX() - doneButton.getWidth() - PAD10, doneButton.getY()); reportButton.setBackground(Color.white); footerLabel.setSize(reportButton.getLocation().x, PAD30); footerLabel.setHorizontalAlignment(JLabel.CENTER); btmPanel.remove(progressBar); btmPanel.add(reportButton); btmPanel.repaint(); doneButton.setText("Done"); doneButton.setIcon(new ImageIcon("img/22x22/play.png", OMLAppDetails.name())); }
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 w ww.j ava 2 s. c o m*/ 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:speedbagalg.OscopeView.java
private void hStartSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_hStartSpinnerStateChanged {//GEN-HEADEREND:event_hStartSpinnerStateChanged int baseTime = (int) hStartSpinner.getValue(); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(false);//from w w w .j a v a 2 s. c o m minStart = baseTime; axis.setRange(minStart, minStart + maxDomain); //System.out.println("Spinner: "+baseTime); }
From source file:speedbagalg.OscopeView.java
private void vMaxSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_vMaxSpinnerStateChanged {//GEN-HEADEREND:event_vMaxSpinnerStateChanged final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setAutoRange(false);// w w w. j a va2 s.c o m vMax = (int) vMaxSpinner.getValue(); axis.setRange(vMin, vMax); }
From source file:com.wattzap.view.Profile.java
@Override public void callback(Messages message, Object o) { double distance = 0.0; switch (message) { case SPEED:/*from w w w . ja v a2 s . c o m*/ Telemetry t = (Telemetry) o; distance = t.getDistanceKM(); break; case STARTPOS: distance = (Double) o; break; case CLOSE: if (this.isVisible()) { remove(chartPanel); setVisible(false); revalidate(); } return; case GPXLOAD: // Note if we are loading a Power Profile there is no GPX data so we don't show the chart panel RouteReader routeData = (RouteReader) o; if (chartPanel != null) { remove(chartPanel); if (routeData.routeType() == RouteReader.POWER) { setVisible(false); chartPanel.revalidate(); return; } } else if (routeData.routeType() == RouteReader.POWER) { return; } logger.debug("Load " + routeData.getFilename()); XYDataset xyDataset = new XYSeriesCollection(routeData.getSeries()); // create the chart... final JFreeChart chart = ChartFactory.createXYAreaChart(routeData.getName(), // chart // title userPrefs.messages.getString("distancekm"), // domain axis label userPrefs.messages.getString("heightMeters"), // range axis label xyDataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend false, // tooltips false // urls ); chart.setBackgroundPaint(Color.darkGray); plot = chart.getXYPlot(); // plot.setForegroundAlpha(0.85f); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); double minY = routeData.getSeries().getMinY(); double maxY = routeData.getSeries().getMaxY(); rangeAxis.setRange(minY - 100.0, maxY + 100.0); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); break; }// switch if (plot == null) { return; } if (marker != null) { plot.removeDomainMarker(marker); } marker = new ValueMarker(distance); marker.setPaint(Color.blue); BasicStroke stroke = new BasicStroke(2); marker.setStroke(stroke); plot.addDomainMarker(marker); }
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);/* w w w . j a v a2 s. c o m*/ 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:speedbagalg.OscopeView.java
/** * Creates new form OscopeView// w ww . java 2 s.c o m */ /* public OscopeView(String fileName) { this.fileName = fileName; initComponents(); updateThread = new RunnableMember2(this, "updateGUI"); ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true)); // create a dataset... int maxAge = 2400; this.xData = new TimeSeries("X axis"); this.xData.setMaximumItemAge(maxAge); this.yData = new TimeSeries("Y axis"); this.yData.setMaximumItemAge(maxAge); this.zData = new TimeSeries("Z axis"); this.zData.setMaximumItemAge(maxAge); this.averageData = new TimeSeries("Avg. Data"); this.averageData.setMaximumItemAge(maxAge); //this.windSpeedSeries = new TimeSeries("Wind Speed"); //this.windSpeedSeries.setMaximumItemAge(maxAge); //this.rainSeries = new TimeSeries("Rain 24hrs"); //this.rainSeries.setMaximumItemAge(maxAge); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(xData); dataset.addSeries(yData); dataset.addSeries(zData); dataset.addSeries(averageData); //dataset.addSeries(windSpeedSeries); //dataset.addSeries(rainSeries); final JFreeChart chart = ChartFactory.createTimeSeriesChart( "Accel Data", "Time", "Value", dataset, true, true, false); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis = plot.getRangeAxis(); axis.setRange(-1000.0, 10000.0); chart.setBackgroundPaint(Color.white); //XYPlot plot = (XYPlot) chart.getPlot(); 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); // create and display a frame... thePanel = new ChartPanel(chart); Dimension d = new Dimension(200, 100); thePanel.setSize(d); thePanel.setPreferredSize(d); BorderLayout layout = new BorderLayout(); jPanelOscope.setLayout(layout); jPanelOscope.add(thePanel, BorderLayout.CENTER); plotXCheckBox.setSelected(plotX); plotYCheckBox.setSelected(plotY); plotZCheckBox.setSelected(plotZ); } */ public OscopeView(String fileName) { this.fileName = fileName; initComponents(); updateThread = new RunnableMember2(this, "updateGUI"); ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true)); // create a dataset... this.xData = new XYSeries("Min"); //this.xData.setMaximumItemAge(maxAge); this.yData = new XYSeries("Peak"); //this.yData.setMaximumItemAge(maxAge); this.zData = new XYSeries("Z axis"); //this.zData.setMaximumItemAge(maxAge); this.averageData = new XYSeries("Avg. Data"); //this.averageData.setMaximumItemAge(maxAge); //this.windSpeedSeries = new TimeSeries("Wind Speed"); //this.windSpeedSeries.setMaximumItemAge(maxAge); //this.rainSeries = new TimeSeries("Rain 24hrs"); //this.rainSeries.setMaximumItemAge(maxAge); final XYSeriesCollection dataset = new XYSeriesCollection(); //SlidingCategoryDataset dataset = new SlidingCategoryDataset(0, 10); dataset.addSeries(xData); dataset.addSeries(yData); dataset.addSeries(zData); dataset.addSeries(averageData); //dataset.addSeries(windSpeedSeries); //dataset.addSeries(rainSeries); chart = ChartFactory.createXYLineChart("Accel Data", "Time", "Value", dataset, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(false); axis.setRange(minStart, maxDomain); axis = plot.getRangeAxis(); axis.setRange(vMin, vMax); chart.setBackgroundPaint(Color.white); //XYPlot plot = (XYPlot) chart.getPlot(); 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); // create and display a frame... thePanel = new ChartPanel(chart); Dimension d = new Dimension(200, 100); thePanel.setSize(d); thePanel.setPreferredSize(d); BorderLayout layout = new BorderLayout(); jPanelOscope.setLayout(layout); jPanelOscope.add(thePanel, BorderLayout.CENTER); plotXCheckBox.setSelected(plotX); plotYCheckBox.setSelected(plotY); plotZCheckBox.setSelected(plotZ); vMaxSpinner.setValue(vMax); }