List of usage examples for org.jfree.chart.plot XYPlot setRangeAxisLocation
public void setRangeAxisLocation(AxisLocation location)
From source file:net.sourceforge.subsonic.controller.StatusChartController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); List<TransferStatus> statuses = Collections.emptyList(); if ("stream".equals(type)) { statuses = statusService.getAllStreamStatuses(); } else if ("download".equals(type)) { statuses = statusService.getAllDownloadStatuses(); } else if ("upload".equals(type)) { statuses = statusService.getAllUploadStatuses(); }//from w w w. ja v a2 s . co m if (index < 0 || index >= statuses.size()) { return null; } TransferStatus status = statuses.get(index); TimeSeries series = new TimeSeries("Kbps", Millisecond.class); TransferStatus.SampleHistory history = status.getHistory(); long to = System.currentTimeMillis(); long from = to - status.getHistoryLengthMillis(); Range range = new DateRange(from, to); if (!history.isEmpty()) { TransferStatus.Sample previous = history.get(0); for (int i = 1; i < history.size(); i++) { TransferStatus.Sample sample = history.get(i); long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp(); long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered()); double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0); series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps); previous = sample; } } // Compute moving average. series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000); // Find min and max values. double min = 100; double max = 250; for (Object obj : series.getItems()) { TimeSeriesDataItem item = (TimeSeriesDataItem) obj; double value = item.getValue().doubleValue(); if (item.getPeriod().getFirstMillisecond() > from) { min = Math.min(min, value); max = Math.max(max, value); } } // Add 10% to max value. max *= 1.1D; // Subtract 10% from min value. min *= 0.9D; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white); plot.setBackgroundPaint(background); XYItemRenderer renderer = plot.getRendererForDataset(dataset); renderer.setSeriesPaint(0, Color.blue.darker()); renderer.setSeriesStroke(0, new BasicStroke(2f)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setRange(range); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(new Range(min, max)); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT); return null; }
From source file:org.madsonic.controller.StatusChartController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); List<TransferStatus> statuses = Collections.emptyList(); if ("stream".equals(type)) { statuses = statusService.getAllStreamStatuses(); } else if ("download".equals(type)) { statuses = statusService.getAllDownloadStatuses(); } else if ("upload".equals(type)) { statuses = statusService.getAllUploadStatuses(); }// w ww. j a v a 2s . c o m if (index < 0 || index >= statuses.size()) { return null; } TransferStatus status = statuses.get(index); TimeSeries series = new TimeSeries("Kbps", Millisecond.class); TransferStatus.SampleHistory history = status.getHistory(); long to = System.currentTimeMillis(); long from = to - status.getHistoryLengthMillis(); Range range = new DateRange(from, to); if (!history.isEmpty()) { TransferStatus.Sample previous = history.get(0); for (int i = 1; i < history.size(); i++) { TransferStatus.Sample sample = history.get(i); long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp(); long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered()); double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0); series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps); previous = sample; } } // Compute moving average. series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000); // Find min and max values. double min = 100; double max = 250; for (Object obj : series.getItems()) { TimeSeriesDataItem item = (TimeSeriesDataItem) obj; double value = item.getValue().doubleValue(); if (item.getPeriod().getFirstMillisecond() > from) { min = Math.min(min, value); max = Math.max(max, value); } } // Add 10% to max value. max *= 1.1D; // Subtract 10% from min value. min *= 0.9D; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white); plot.setBackgroundPaint(background); XYItemRenderer renderer = plot.getRendererForDataset(dataset); renderer.setSeriesPaint(0, Color.gray.darker()); renderer.setSeriesStroke(0, new BasicStroke(2f)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setRange(range); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(new Range(min, max)); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT); return null; }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawStandardXYPlot(Shape shape, Color color, int minSignal, int maxSignal) { // Set up renderer StandardXYItemRenderer batteryRenderer = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES_AND_LINES); batteryRenderer.setAutoPopulateSeriesShape(false); batteryRenderer.setBaseShape(shape); batteryRenderer.setSeriesPaint(0, color); // Normalize the throughput axis so that it represents max value NumberAxis axis = new NumberAxis(); axis.setVisible(false);//from w w w. j a v a2s .c o m axis.setAutoRange(false); axis.setRange(minSignal, maxSignal); // Create plot XYPlot barPlot = new XYPlot(null, null, axis, batteryRenderer); barPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); barPlot.getRangeAxis().setVisible(false); return barPlot; }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawXYItemPlot() { // Set up renderer XYItemRenderer throughputRenderer = new StandardXYItemRenderer(); throughputRenderer.setSeriesPaint(0, Color.red); // Normalize the throughput axis so that it represents max value NumberAxis axis = new NumberAxis(); axis.setVisible(false);// w w w . j a v a 2 s.c om // Create plot XYPlot throughputPlot = new XYPlot(null, null, axis, throughputRenderer); throughputPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); throughputPlot.getRangeAxis().setVisible(false); return throughputPlot; }
From source file:org.jfree.chart.demo.CombinedXYPlotDemo4.java
/** * Creates a combined chart./*from w w w . ja v a2 s .c o m*/ * * @return The combined chart. */ private JFreeChart createCombinedChart() { // create subplot 1... final XYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // add secondary axis subplot1.setDataset(1, createDataset2()); final NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); subplot1.setRangeAxis(1, axis2); subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); subplot1.setRenderer(1, new StandardXYItemRenderer()); subplot1.mapDatasetToRangeAxis(1, 1); final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:com.yahoo.egads.utilities.GUIUtils.java
/** * Creates a combined chart.//from w ww. j a va 2s.c om * * @return The combined chart. */ private JFreeChart createCombinedChart(DataSequence tsOne, DataSequence tsTwo, ArrayList<Anomaly> anomalyList) { // create subplot 1. final XYDataset data1 = createDataset(tsOne, "Original"); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Original Value"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // plot anomalies on subplot 1. addAnomalies(subplot1, anomalyList); // create subplot 2. final XYDataset data2 = createDataset(tsTwo, "Forecast"); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Forecast Value"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot. final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time")); plot.setGap(10.0); // add the subplots. plot.add(subplot1, 1); plot.add(subplot2, 1); // Add anomaly score time-series. addAnomalyTS(plot, tsOne, tsTwo); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot. return new JFreeChart("EGADS GUI", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:ascensionxyplot.AscensionXYPlot.java
/** * Creates a combined chart./*from ww w .j av a2s. c om*/ * * @return The combined chart. */ private JFreeChart createCombinedChart(File dataFile) { // create subplot 1... final XYDataset data1 = createDataset1(dataFile); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // add secondary axis // subplot1.setDataset(1, createDataset2()); // final NumberAxis axis2 = new NumberAxis("Range Axis 2"); // axis2.setAutoRangeIncludesZero(false); // subplot1.setRangeAxis(1, axis2); // subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // subplot1.setRenderer(1, new StandardXYItemRenderer()); // subplot1.mapDatasetToRangeAxis(1, 1); final XYTextAnnotation annotation1 = new XYTextAnnotation("x value", 20.0, 120000.0); final XYTextAnnotation annotation2 = new XYTextAnnotation("y value", 20.0, 110000.0); final XYTextAnnotation annotation3 = new XYTextAnnotation("z value", 20.0, 100000.0); final XYTextAnnotation annotation4 = new XYTextAnnotation("timepoint", 20.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation4.setFont(new Font("SansSerif", Font.PLAIN, 9)); // annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation1); subplot1.addAnnotation(annotation2); subplot1.addAnnotation(annotation3); subplot1.addAnnotation(annotation4); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("Is this the title?", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:crossspectrumapp.CrossSpectrumApp.java
private void plotData(double[] frequency, double[] power, double[] phase, String title, String subTitleText1, String subTitleText2) throws WebUtilException { XYSeries asdSeries = new XYSeries("asd"); XYSeries phiSeries = new XYSeries("phase"); for (int i = 1; i < frequency.length; i++) { double f = frequency[i]; double pwr = power[i]; double phi = phase[i]; asdSeries.add(f, pwr);/* www . j ava 2s .c o m*/ phiSeries.add(f, phi); } XYSeriesCollection asdCollection = new XYSeriesCollection(); asdCollection.addSeries(asdSeries); XYSeriesCollection phiCollection = new XYSeriesCollection(); phiCollection.addSeries(phiSeries); // create the chart XYItemRenderer asdRenderer = new StandardXYItemRenderer(); LogAxis asdAxis = new LogAxis("ASD counts/ \u221AHz"); XYPlot asdSubplot = new XYPlot(asdCollection, null, asdAxis, asdRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYItemRenderer phiRenderer = new StandardXYItemRenderer(); NumberAxis phiAxis = new NumberAxis("Phase degrees"); XYPlot phiSubplot = new XYPlot(phiCollection, null, phiAxis, phiRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new LogAxis("Frequency (Hz)")); plot.setGap(10.0); // add the subplots... plot.add(asdSubplot, 2); plot.add(phiSubplot, 1); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); Title subTitle = new TextTitle(subTitleText1); chart.addSubtitle(subTitle); subTitle = new TextTitle(subTitleText2); chart.addSubtitle(subTitle); ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); panel.setPreferredSize(new java.awt.Dimension(cscl.getOutX(), cscl.getOutY())); FileOutputStream fos = null; try { fos = new FileOutputStream(cscl.getOfileName()); ChartUtilities.writeChartAsPNG(fos, chart, cscl.getOutX(), cscl.getOutY()); fos.close(); fos = null; } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } } }
From source file:com.yahoo.egads.utilities.GUIUtils.java
/** * Compute the time-series of anomalies. */// www . ja v a 2s .co m public void addAnomalyTS(CombinedDomainXYPlot plot, DataSequence observedSeries, DataSequence expectedSeries) { // Compute the time-series of errors. HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries); Float sDAutoSensitivity = (float) 0.0; Float amntAutoSensitivity = (float) 0.0; if (config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT") != null) { amntAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT")); } if (config.getProperty("AUTO_SENSITIVITY_SD") != null) { sDAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_SD")); } String errorDebug = ""; for (int i = 0; i < (aes.getIndexToError().keySet()).size(); i++) { Float[] fArray = (allErrors.get(aes.getIndexToError().get(i))) .toArray(new Float[(allErrors.get(aes.getIndexToError().get(i))).size()]); XYDataset data1 = createDataset(fArray, aes.getIndexToError().get(i)); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis(aes.getIndexToError().get(i)); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); // Get threshold. Float d = AutoSensitivity.getLowDensitySensitivity(fArray, sDAutoSensitivity, amntAutoSensitivity); subplot1.addRangeMarker(new ValueMarker(d)); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.add(subplot1, 1); errorDebug += aes.getIndexToError().get(i) + ": " + d + " "; } System.out.println(errorDebug); }
From source file:org.jstockchart.plot.TimeseriesPlot.java
private XYPlot createPricePlot() { Font axisFont = new Font("Arial", 0, 12); Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); PriceArea priceArea = timeseriesArea.getPriceArea(); Color averageColor = new Color(243, 182, 117); priceArea.setAverageColor(averageColor); priceArea.setPriceColor(Color.BLUE); TimeSeriesCollection priceDataset = new TimeSeriesCollection(); priceDataset.addSeries(dataset.getPriceTimeSeries().getTimeSeries()); if (priceArea.isAverageVisible()) { priceDataset.addSeries(dataset.getAverageTimeSeries().getTimeSeries()); }// w w w .jav a 2s.c o m CentralValueAxis logicPriceAxis = priceArea.getLogicPriceAxis(); logicPriceAxis.setTickCount(7); CFXNumberAxis priceAxis = new CFXNumberAxis(logicPriceAxis.getLogicTicks()); priceAxis.setShowUD(true); priceAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); priceAxis.setTickMarksVisible(false); XYLineAndShapeRenderer priceRenderer = new XYLineAndShapeRenderer(true, false); priceAxis.setUpperBound(logicPriceAxis.getUpperBound()); priceAxis.setLowerBound(logicPriceAxis.getLowerBound()); priceAxis.setAxisLineVisible(false); priceAxis.setTickLabelFont(axisFont); priceRenderer.setSeriesPaint(0, priceArea.getPriceColor()); priceRenderer.setSeriesPaint(1, priceArea.getAverageColor()); CFXNumberAxis rateAxis = new CFXNumberAxis(logicPriceAxis.getRatelogicTicks()); rateAxis.setShowUD(true); rateAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); rateAxis.setTickMarksVisible(false); ; rateAxis.setTickLabelFont(axisFont); rateAxis.setAxisLineVisible(false); rateAxis.setUpperBound(logicPriceAxis.getUpperBound()); rateAxis.setLowerBound(logicPriceAxis.getLowerBound()); XYPlot plot = new XYPlot(priceDataset, null, priceAxis, priceRenderer); plot.setBackgroundPaint(priceArea.getBackgroudColor()); plot.setOrientation(priceArea.getOrientation()); plot.setRangeAxisLocation(priceArea.getPriceAxisLocation()); plot.setRangeMinorGridlinesVisible(false); Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 2.0f, 2.0f }, 1.0f); plot.setRangeGridlineStroke(gridLineStroke); plot.setDomainGridlineStroke(gridLineStroke); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setOutlineVisible(true); plot.setOutlineStroke(outLineStroke); plot.setOutlinePaint(Color.BLACK); if (priceArea.isRateVisible()) { plot.setRangeAxis(1, rateAxis); plot.setRangeAxisLocation(1, priceArea.getRateAxisLocation()); plot.setDataset(1, null); plot.mapDatasetToRangeAxis(1, 1); } if (priceArea.isMarkCentralValue()) { Number centralPrice = logicPriceAxis.getCentralValue(); if (centralPrice != null) { plot.addRangeMarker(new ValueMarker(centralPrice.doubleValue(), priceArea.getCentralPriceColor(), new BasicStroke())); } } return plot; }