List of usage examples for org.jfree.chart.plot XYPlot setRangeAxis
public void setRangeAxis(ValueAxis axis)
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample time series chart. * * @return a sample time series chart.// w w w.j av a 2 s. c om */ public JFreeChart createTimeSeries2Chart() { // create a default chart based on some sample data... final String title = this.resources.getString("timeseries.sample2.title"); final String subtitleStr = this.resources.getString("timeseries.sample2.subtitle"); final String domain = this.resources.getString("timeseries.sample2.domain"); final String range = this.resources.getString("timeseries.sample2.range"); final XYDataset data = DemoDatasetFactory.createTimeSeriesCollection4(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data, true, true, false); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final XYPlot plot = chart.getXYPlot(); final LogarithmicAxis rangeAxis = new LogarithmicAxis(range); plot.setRangeAxis(rangeAxis); return chart; }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
protected void setChartAxes(JFreeChart chart, UIChart comp) { UIAxis xAxis = comp.getxAxis();//w w w . j av a2 s. co m UIAxis yAxis = comp.getyAxis(); String xAxisLabel = comp.getxAxisLabel(); String yAxisLabel = comp.getyAxisLabel(); Plot plot = chart.getPlot(); Axis domainAxis = null; Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) plot; if (yAxis != null && yAxis.isLogarithmic()) categoryPlot.setRangeAxis(new LogarithmicAxis(null)); domainAxis = categoryPlot.getDomainAxis(); rangeAxis = categoryPlot.getRangeAxis(); if (xAxis != null) { Boolean drawGridLine = xAxis.getDrawGridLine(); if (drawGridLine != null) { categoryPlot.setDomainGridlinesVisible(drawGridLine); } Paint gridLineColor = xAxis.getGridLineColor(); if (gridLineColor != null) { categoryPlot.setDomainGridlinePaint(gridLineColor); } } if (yAxis != null) { Boolean drawGridLine = yAxis.getDrawGridLine(); if (drawGridLine != null) { categoryPlot.setRangeGridlinesVisible(drawGridLine); } Paint gridLineColor = yAxis.getGridLineColor(); if (gridLineColor != null) { categoryPlot.setRangeGridlinePaint(gridLineColor); } } } else if (plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; if (xAxis != null && xAxis.isLogarithmic()) xyPlot.setDomainAxis(new LogarithmicAxis(null)); if (yAxis != null && yAxis.isLogarithmic()) xyPlot.setRangeAxis(new LogarithmicAxis(null)); domainAxis = xyPlot.getDomainAxis(); rangeAxis = xyPlot.getRangeAxis(); if (xAxis != null) { Boolean drawGridLine = xAxis.getDrawGridLine(); if (drawGridLine != null) { xyPlot.setDomainGridlinesVisible(drawGridLine); } Paint gridLineColor = xAxis.getGridLineColor(); if (gridLineColor != null) { xyPlot.setDomainGridlinePaint(gridLineColor); } Boolean drawBaseLine = xAxis.getDrawBaseLine(); if (drawBaseLine != null) { xyPlot.setDomainZeroBaselineVisible(drawBaseLine); } Paint baseLineColor = xAxis.getBaseLineColor(); if (baseLineColor != null) { xyPlot.setDomainZeroBaselinePaint(baseLineColor); } } if (yAxis != null) { Boolean drawGridLine = yAxis.getDrawGridLine(); if (drawGridLine != null) { xyPlot.setRangeGridlinesVisible(drawGridLine); } Paint gridLineColor = yAxis.getGridLineColor(); if (gridLineColor != null) { xyPlot.setRangeGridlinePaint(gridLineColor); } Boolean drawBaseLine = yAxis.getDrawBaseLine(); if (drawBaseLine != null) { xyPlot.setRangeZeroBaselineVisible(drawBaseLine); } Paint baseLineColor = yAxis.getBaseLineColor(); if (baseLineColor != null) { xyPlot.setRangeZeroBaselinePaint(baseLineColor); } } } if (domainAxis != null) { if (xAxisLabel != null) domainAxis.setLabel(xAxisLabel); if (xAxis != null) setAxisStyles(domainAxis, xAxis); } if (rangeAxis != null) { if (yAxisLabel != null) rangeAxis.setLabel(yAxisLabel); if (yAxis != null) setAxisStyles(rangeAxis, yAxis); } }
From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java
private JFreeChart createChart() { JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); XYPlot plot = result.getXYPlot(); plot.setDataset(DFM_INDEX, Charts.emptyXYDataset()); plot.setRenderer(DFM_INDEX, dfmRenderer); plot.mapDatasetToDomainAxis(DFM_INDEX, 0); plot.mapDatasetToRangeAxis(DFM_INDEX, 0); plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset()); plot.setRenderer(ARIMA_INDEX, arimaRenderer); plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0); plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0); plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset()); plot.setRenderer(STDEV_INDEX, stdevRenderer); plot.mapDatasetToDomainAxis(STDEV_INDEX, 0); plot.mapDatasetToRangeAxis(STDEV_INDEX, 0); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); NumberAxis domainAxis = new NumberAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis);//from w w w . jav a2s .c o m return result; }
From source file:be.nbb.demetra.dfm.output.ConfidenceGraph.java
private JFreeChart createMarginViewChart() { final JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); XYPlot plot = result.getXYPlot(); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); XYLineAndShapeRenderer main = new LineRenderer(MAIN_INDEX); plot.setRenderer(MAIN_INDEX, main);//from w ww . j a v a 2 s.co m XYLineAndShapeRenderer original = new LineRenderer(ORIGINAL_DATA_INDEX); plot.setRenderer(ORIGINAL_DATA_INDEX, original); for (int i = 0; i < indexes.length - 1; i++) { plot.setRenderer(indexes[i], getDifferenceRenderer()); for (int j = 1; j < intermediateValues; j++) { plot.setRenderer(indexes[i] - j, getDifferenceRenderer()); } } plot.setRenderer(CONFIDENCE99_INDEX, getDifferenceRenderer()); DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); return result; }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputScatter.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);/*ww w . j av a 2 s . c o m*/ pp.getDomainAxis().setAxisLinePaint(axesColor); pp.getDomainAxis().setTickLabelFont(getTickFont()); pp.getDomainAxis().setLabelFont(getLabelFont()); if (textColor != null) { pp.getDomainAxis().setLabelPaint(textColor); pp.getDomainAxis().setTickLabelPaint(textColor); } NumberAxis axis = (NumberAxis) pp.getRangeAxis(); axis = formatYAxis(scope, axis); pp.setRangeAxis(axis); if (ytickunit > 0) { ((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit)); pp.setRangeGridlinesVisible(true); } else pp.setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue()); // resetAutorange(scope); if (getType() == ChartOutput.SERIES_CHART) { if (xlabel == null) xlabel = "time"; } if (getType() == ChartOutput.XY_CHART) { } if (getType() == ChartOutput.SCATTER_CHART) { } if (!this.getXTickValueVisible(scope)) { pp.getDomainAxis().setTickMarksVisible(false); pp.getDomainAxis().setTickLabelsVisible(false); } }
From source file:ec.util.chart.swing.JTimeSeriesChart.java
private void growSubPlots(int size) { for (int i = 0; i < size; i++) { XYPlot plot = new XYPlot(); for (int rendererIndex = 0; rendererIndex < supportedRendererTypes.size(); rendererIndex++) { SeriesIndexResolver resolver = SeriesIndexResolver.create(plot, rendererIndex); JTimeSeriesRendererSupport support = new RendererSupport(resolver); plot.setRenderer(rendererIndex, support.createRenderer(supportedRendererTypes.get(rendererIndex))); }/* w ww .j a v a 2 s . c o m*/ NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelInsets(new RectangleInsets(10, 5, 10, 2)); rangeAxis.setLowerMargin(0.02); rangeAxis.setUpperMargin(0.02); plot.setRangeAxis(rangeAxis); mainPlot.add(plot); onDatasetChange(plot); onColorSchemeSupportChange(plot); onValueFormatChange(plot); onNoDataMessageChange(plot); onElementVisibleChange(plot); onFontSupportChange(plot); } }
From source file:com.zimbra.perf.chart.ChartUtil.java
private List<JFreeChart> createJFReeChart(ChartSettings cs) { double minValue = Double.MAX_VALUE; double maxValue = Double.MIN_VALUE; double d = 0; double count = 0; double total = 0; TimeSeriesCollection data = new TimeSeriesCollection(); ArrayList<ChartSettings> syntheticSettings = new ArrayList<ChartSettings>(); for (GroupPlotSettings gps : cs.getGroupPlots()) { String groupBy = gps.getGroupBy(); DataColumn dc = new DataColumn(gps.getInfile(), groupBy); StringSeries groupBySeries = mStringSeries.get(dc); dc = new DataColumn(gps.getInfile(), gps.getDataColumn()); DataSeries ds = mDataSeries.get(dc); int idx = 0; Map<String, List<Integer>> groups = new HashMap<String, List<Integer>>(); for (StringEntry e : groupBySeries.dataCollection) { String g = e.getVal(); List<Integer> indices = groups.get(g); if (indices == null) { indices = new ArrayList<Integer>(); groups.put(g, indices);/*from w w w.jav a 2 s . co m*/ } indices.add(idx); idx++; } for (Map.Entry<String, List<Integer>> g : groups.entrySet()) { String groupByValue = g.getKey(); if (gps.getIgnoreSet().contains(groupByValue)) continue; List<Integer> indices = g.getValue(); DataSeries syntheticDS = new DataSeries(); DataColumn c = new DataColumn(gps.getInfile(), GROUP_PLOT_SYNTHETIC + groupByValue + ":" + gps.getDataColumn()); for (int i : indices) { Entry e = ds.get(i); syntheticDS.AddEntry(e.getTimestamp(), e.getVal()); } mDataSeries.put(c, syntheticDS); PlotSettings syntheticPlot = new PlotSettings(groupByValue, c.getInfile(), c.getColumn(), gps.getShowRaw(), gps.getShowMovingAvg(), gps.getMovingAvgPoints(), gps.getMultiplier(), gps.getDivisor(), gps.getNonNegative(), gps.getPercentTime(), gps.getDataFunction(), gps.getAggregateFunction(), gps.getOptional(), null, null); cs.addPlot(syntheticPlot); if (cs.getOutDocument() != null) { ChartSettings s = new ChartSettings(String.format(cs.getTitle(), groupByValue), cs.getCategory(), String.format(cs.getOutfile(), groupByValue), cs.getXAxis(), cs.getYAxis(), cs.getAllowLogScale(), cs.getPlotZero(), cs.getWidth(), cs.getHeight(), null, cs.getTopPlots(), cs.getTopPlotsType()); s.addPlot(syntheticPlot); syntheticSettings.add(s); } } } if (cs.getOutDocument() != null && cs.getGroupPlots().size() != 0) { ArrayList<JFreeChart> charts = new ArrayList<JFreeChart>(); for (ChartSettings c : syntheticSettings) { charts.addAll(createJFReeChart(c)); c.setOutDocument(cs.getOutDocument()); } mSyntheticChartSettings.addAll(syntheticSettings); return charts; } List<PlotSettings> plots = cs.getPlots(); if (cs.getTopPlots() > 0 && plots.size() > cs.getTopPlots()) { String aggregateFunction = cs.getTopPlotsType().name().toLowerCase(); System.out.println(String.format("Reducing %d to %d plots for chart '%s'", plots.size(), cs.getTopPlots(), cs.getTitle())); ArrayList<PlotAggregatePair> aggregates = new ArrayList<PlotAggregatePair>(); for (PlotSettings ps : plots) { DataColumn dc = new DataColumn(ps.getInfile(), ps.getDataColumn()); String key = ps.getInfile() + ":" + ps.getDataColumn() + ":" + ps.getAggregateFunction(); PlotDataIterator pdIter = new PlotDataIterator(ps, mDataSeries.get(dc)); double aggregate = mAggregator.compute(pdIter, aggregateFunction, mAggregateStartAt, mAggregateEndAt, key); aggregates.add(new PlotAggregatePair(ps, aggregate)); } Collections.sort(aggregates); while (aggregates.size() > cs.getTopPlots()) { PlotAggregatePair pair = aggregates.remove(0); plots.remove(pair.ps); } } for (PlotSettings ps : plots) { String columnName = ps.getDataColumn(); if (columnName == null) { columnName = RATIO_PLOT_SYNTHETIC + ps.getRatioTop() + "/" + ps.getRatioBottom(); String infile = ps.getInfile(); String[] top = ps.getRatioTop().split("\\+"); String[] bottom = ps.getRatioBottom().split("\\+"); DataColumn[] ratioTop = new DataColumn[top.length]; DataColumn[] ratioBottom = new DataColumn[bottom.length]; for (int i = 0, j = top.length; i < j; i++) ratioTop[i] = new DataColumn(infile, top[i]); for (int i = 0, j = bottom.length; i < j; i++) ratioBottom[i] = new DataColumn(infile, bottom[i]); DataSeries[] topData = new DataSeries[ratioTop.length]; DataSeries[] bottomData = new DataSeries[ratioBottom.length]; for (int i = 0, j = ratioTop.length; i < j; i++) topData[i] = mDataSeries.get(ratioTop[i]); for (int i = 0, j = ratioBottom.length; i < j; i++) bottomData[i] = mDataSeries.get(ratioBottom[i]); DataSeries ds = new DataSeries(); for (int i = 0, j = topData[0].size(); i < j; i++) { double topValue = 0.0; double bottomValue = 0.0; double ratio = 0.0; Entry lastEntry = null; for (int m = 0, n = topData.length; m < n; m++) { Entry e = topData[m].get(i); topValue += e.getVal(); } for (int m = 0, n = bottomData.length; m < n; m++) { Entry e = bottomData[m].get(i); bottomValue += e.getVal(); lastEntry = e; } if (bottomValue != 0.0) { ratio = topValue / bottomValue; } // should never be null assert lastEntry != null; ds.AddEntry(lastEntry.getTimestamp(), ratio); } mDataSeries.put(new DataColumn(infile, columnName), ds); ps.setDataColumn(columnName); } DataColumn dc = new DataColumn(ps.getInfile(), ps.getDataColumn()); DataSeries ds = mDataSeries.get(dc); TimeSeries ts = new TimeSeries(ps.getLegend(), FixedMillisecond.class); int numSamples = 0; for (PlotDataIterator pdIter = new PlotDataIterator(ps, ds); pdIter.hasNext(); numSamples++) { Pair<Date, Double> entry = pdIter.next(); Date tstamp = entry.getFirst(); double val = entry.getSecond().doubleValue(); if (val != 0 || cs.getPlotZero()) { if (d < minValue) minValue = val; if (d > maxValue) maxValue = val; count++; total += val; try { ts.addOrUpdate(new FixedMillisecond(tstamp), val); } catch (SeriesException e) { e.printStackTrace(System.out); } } } if (numSamples == 0 && ps.getOptional()) { System.out.format("Skipping optional plot %s (no data sample found)\n\n", ps.getLegend()); continue; } System.out.format("Adding %d %s points to %s.\n\n", ds.size(), ps.getLegend(), cs.getOutfile()); if (ps.getShowRaw()) { data.addSeries(ts); } if (ps.getShowMovingAvg()) { int numPoints = ps.getMovingAvgPoints(); if (numPoints == PlotSettings.DEFAULT_PLOT_MOVING_AVG_POINTS) { // Display 200 points for moving average. // Divide the total number of points by 200 to // determine the number of samples to average // for each point. numPoints = ts.getItemCount() / 200; } if (numPoints >= 2) { TimeSeries ma = MovingAverage.createPointMovingAverage(ts, ps.getLegend() + " (moving avg)", numPoints); data.addSeries(ma); } else { System.out.println("Not enough data to display moving average for " + ps.getLegend()); data.addSeries(ts); } } } // Create chart boolean legend = (data.getSeriesCount() > 1); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, cs.getXAxis(), cs.getYAxis(), data, legend, false, false); // Make Y-axis logarithmic if a spike was detected if (cs.getAllowLogScale() && (minValue > 0) && (maxValue > 0) && (maxValue > 20 * (total / count))) { if (maxValue / minValue > 100) { XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis oldAxis = plot.getRangeAxis(); LogarithmicAxis newAxis = new LogarithmicAxis(oldAxis.getLabel()); plot.setRangeAxis(newAxis); } } mChartMap.put(cs, chart); return Arrays.asList(chart); }
From source file:com.android.ddmuilib.net.NetworkPanel.java
/** * Create chart of recent network activity. *//*from w w w . ja v a2 s . c o m*/ private void createChart() { mChart = ChartFactory.createTimeSeriesChart(null, null, null, null, false, false, false); // create backing datasets and series mRxTotalSeries = new TimeSeries("RX total"); mTxTotalSeries = new TimeSeries("TX total"); mRxTotalSeries.setMaximumItemAge(HISTORY_MILLIS); mTxTotalSeries.setMaximumItemAge(HISTORY_MILLIS); mTotalCollection = new TimeSeriesCollection(); mTotalCollection.addSeries(mRxTotalSeries); mTotalCollection.addSeries(mTxTotalSeries); mRxDetailDataset = new LiveTimeTableXYDataset(); mTxDetailDataset = new LiveTimeTableXYDataset(); mTotalRenderer = new XYAreaRenderer(XYAreaRenderer.AREA); mRenderer = new StackedXYAreaRenderer2(); final XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); xyPlot.setDataset(0, mTotalCollection); xyPlot.setDataset(1, mRxDetailDataset); xyPlot.setDataset(2, mTxDetailDataset); xyPlot.setRenderer(0, mTotalRenderer); xyPlot.setRenderer(1, mRenderer); xyPlot.setRenderer(2, mRenderer); // we control domain axis manually when taking samples mDomainAxis = xyPlot.getDomainAxis(); mDomainAxis.setAutoRange(false); final NumberAxis axis = new NumberAxis(); axis.setNumberFormatOverride(new BytesFormat(true)); axis.setAutoRangeMinimumSize(50); xyPlot.setRangeAxis(axis); xyPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); // draw thick line to separate RX versus TX traffic xyPlot.addRangeMarker(new ValueMarker(0, java.awt.Color.BLACK, new java.awt.BasicStroke(2))); // label to indicate that positive axis is RX traffic final ValueMarker rxMarker = new ValueMarker(0); rxMarker.setStroke(new java.awt.BasicStroke(0)); rxMarker.setLabel("RX"); rxMarker.setLabelFont(rxMarker.getLabelFont().deriveFont(30f)); rxMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY); rxMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); rxMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); xyPlot.addRangeMarker(rxMarker); // label to indicate that negative axis is TX traffic final ValueMarker txMarker = new ValueMarker(0); txMarker.setStroke(new java.awt.BasicStroke(0)); txMarker.setLabel("TX"); txMarker.setLabelFont(txMarker.getLabelFont().deriveFont(30f)); txMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY); txMarker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); txMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); xyPlot.addRangeMarker(txMarker); mChartComposite = new ChartComposite(mPanel, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 4096, 4096, true, true, true, true, false, true); final FormData data = new FormData(); data.top = new FormAttachment(mHeader); data.left = new FormAttachment(0); data.bottom = new FormAttachment(70); data.right = new FormAttachment(100); mChartComposite.setLayoutData(data); }
From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java
private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solution) {/* w ww .j ava2s.c o m*/ XYPlot plot = new XYPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem); plot.setDataset(0, problem); plot.setRenderer(0, problemRenderer); XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments); plot.setDataset(1, shipments); plot.setRenderer(1, shipmentsRenderer); if (solution != null) { XYItemRenderer solutionRenderer = getRouteRenderer(solution); plot.setDataset(2, solution); plot.setRenderer(2, solutionRenderer); } NumberAxis xAxis = new NumberAxis(); NumberAxis yAxis = new NumberAxis(); if (boundingBox == null) { xAxis.setRangeWithMargins(getDomainRange(problem)); yAxis.setRangeWithMargins(getRange(problem)); } else { xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX)); yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY)); } plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); return plot; }
From source file:edu.fullerton.viewerplugin.TsPlot.java
@Override public ArrayList<Integer> makePlot(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException { int imageId;//from www .ja v a2 s . c o m try { if (parameterMap.containsKey("ts_newplt")) { imageId = makeAddPlotFiles(dbufs, compact); } else { String gtitle = getTitle(dbufs, compact); XYSeriesCollection xyds = new XYSeriesCollection(); TimeSeriesCollection mtds = new TimeSeriesCollection(); compact = dbufs.size() > 2 ? false : compact; for (ChanDataBuffer dbuf : dbufs) { if (timeAxis.equalsIgnoreCase("utc")) { addTimeSeries(dbuf, compact, mtds); } else { addXySeries(dbuf, compact, xyds); } } Double minx, miny, maxx, maxy; Double[] rng = new Double[4]; if (timeAxis.equalsIgnoreCase("utc")) { PluginSupport.getRangeLimits(mtds, rng); } else { PluginSupport.getRangeLimits(xyds, rng, 0); } minx = rng[0]; miny = rng[1]; maxx = rng[2]; maxy = rng[3]; int exp; if (timeAxis.equalsIgnoreCase("utc")) { exp = PluginSupport.scaleRange(mtds, miny, maxy); } else { exp = PluginSupport.scaleRange(xyds, miny, maxy); } ChartPanel cpnl; DefaultXYDataset ds = new DefaultXYDataset(); JFreeChart chart; if (timeAxis.equalsIgnoreCase("utc")) { chart = ChartFactory.createTimeSeriesChart(gtitle, "Time (UTC)", "Amplitude (Counts)", ds, true, true, false); } else { chart = ChartFactory.createXYLineChart(gtitle, xAxisLabel, "Amplitude (Counts)", ds, PlotOrientation.VERTICAL, true, false, false); } XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = new NumberAxis("Amplitude (Counts)"); ScaledAxisNumberFormat sanf = new ScaledAxisNumberFormat(); sanf.setExp(exp); if (maxy != 0 && Math.abs(maxy - miny) <= Math.abs(maxy) * 1e-25) { // this garbage is to get jFreeChart to put labels on the Y axis double dt = Math.abs(miny) / 10; double scaledMin = (miny - dt) * Math.pow(10., exp); double scaledMax = (maxy + dt) * Math.pow(10., exp); rangeAxis.setRange(scaledMin, scaledMax); NumberTickUnit unit = new NumberTickUnit((scaledMax - scaledMin) / 10.); rangeAxis.setTickUnit(unit); rangeAxis.setAutoRange(false); } // else // { // sanf.setMinMax(miny, maxy); // rangeAxis.setRange(miny, maxy); // NumberTickUnit unit = new NumberTickUnit((maxy - miny)/6.); // rangeAxis.setTickUnit(unit); // rangeAxis.setAutoRange(false); // } rangeAxis.setNumberFormatOverride(sanf); rangeAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(rangeAxis); if (timeAxis.equalsIgnoreCase("utc")) { plot.setDataset(0, mtds); } else { plot.setDataset(0, xyds); } // Set the line thickness XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); BasicStroke str = new BasicStroke(lineThickness); int n = plot.getSeriesCount(); for (int i = 0; i < n; i++) { r.setSeriesStroke(i, str); } plot.setBackgroundPaint(Color.WHITE); // add plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); r.setBaseFillPaint(Color.WHITE); if (compact) { chart.removeLegend(); } chart.setBackgroundPaint(Color.WHITE); cpnl = new ChartPanel(chart); imageId = saveImageAsPNG(cpnl); } } catch (LdvTableException | NoSuchAlgorithmException | SQLException | IOException ex) { throw new WebUtilException("Making time series plot: ", ex); } ArrayList<Integer> ret = new ArrayList<Integer>(); ret.add(imageId); return ret; }