List of usage examples for org.jfree.chart.plot XYPlot setFixedRangeAxisSpace
public void setFixedRangeAxisSpace(AxisSpace space)
From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java
/** * @param folderToWrite Folder to write the resulted charts. * @param plots Collections of plots.//from ww w . jav a 2 s . co m * @param infoMap Map with additional plot info. * @param mode Generation mode. * @throws Exception If failed. */ private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots, Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception { ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); int idx = -1; while (true) { idx++; DefaultXYDataset dataSet = new DefaultXYDataset(); List<JFreeChartPlotInfo> infoList = new ArrayList<>(); String xAxisLabel = ""; String yAxisLabel = ""; String plotName = ""; int cnt = 0; for (List<PlotData> plotData0 : plots) { if (plotData0.size() <= idx) continue; PlotData plotData = plotData0.get(idx); dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data); xAxisLabel = plotData.xAxisLabel; yAxisLabel = plotData.yAxisLabel; plotName = plotData.plotName(); infoList.add(info(plotData.series(), mode)); } if (infoList.isEmpty()) break; JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet, PlotOrientation.VERTICAL, false, false, false); AxisSpace as = new AxisSpace(); as.add(150, RectangleEdge.LEFT); XYPlot plot = (XYPlot) chart.getPlot(); BasicStroke stroke = new BasicStroke(1); plot.setRenderer(renderer); plot.setBackgroundPaint(WHITE); plot.setRangeGridlinePaint(GRAY); plot.setDomainGridlinePaint(GRAY); plot.setFixedRangeAxisSpace(as); plot.setOutlineStroke(stroke); for (int i = 0; i < infoList.size(); i++) { Color color = PLOT_COLORS[i % PLOT_COLORS.length]; renderer.setSeriesPaint(i, color); renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness. infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2)); } ValueAxis axis = plot.getRangeAxis(); Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5); axis.setTickLabelFont(font); axis.setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getDomainAxis().setLabelFont(font); chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30))); File res = new File(folderToWrite, plotName + ".png"); ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info); infoMap.put(res.getAbsolutePath(), infoList); println("Chart is saved to file: ", res); } }
From source file:ru.spbspu.viewer.DataView.java
/** * ? ? //from ww w.j a va2 s. com */ public void buildOscillogram() { CategoryTableXYDataset serie = new CategoryTableXYDataset(); serie.setNotify(false); double step = 1.0 / getDiscretization(); double startPosition = step * getFramePosition(); double[] data = null; if (LPF.isSelected()) { data = _presenter.lpFilter(_presenter.getFrameData(getFramePosition(), getFrameWidth()), Double.parseDouble(spinnerLimitFreq.getValue().toString())); } else { data = _presenter.getFrameData(getFramePosition(), getFrameWidth()); } for (int i = 0; i < data.length; i++) { serie.add(startPosition, data[i], ""); startPosition += step; } JFreeChart chart = ChartFactory.createXYLineChart("", "t,c", "g, /c^2", serie); chart.removeLegend(); chart.setAntiAlias(false); XYPlot plot = chart.getXYPlot(); plot.setFixedRangeAxisSpace(GRAPHIC_SPACE); //plot.setRangeGridlinePaint(Color.BLACK); org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis(); Range range = _presenter.getMinMaxRange(); if (range.getLength() > 0) { yAxis.setRange(range); } org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis(); double start = getFramePosition() * 1.0 / getDiscretization(); double max = start + getFrameWidth() * 1.0 / getDiscretization(); xAxis.setRange(start, max); ChartPanel chartPanel = new ChartPanel(chart); drawGraphOfSignal(chartPanel); }
From source file:ru.spbspu.viewer.DataView.java
/** * ? ? ? ?//from www. j a v a2 s .c o m */ public void buildFullEnergyGraph() { CategoryTableXYDataset serie = new CategoryTableXYDataset(); serie.setNotify(false); double step = 1.0 / getDiscretization() * Integer.parseInt(spinnerWindowWidth.getValue().toString()) / 2; double startPosition = 0; double[] data = _presenter.getFullFrameEnergy(getWindowWidth()); for (int i = 0; i < data.length; i++) { serie.add(startPosition, data[i], ""); startPosition += step; } JFreeChart chart = ChartFactory.createXYLineChart("", "", "t,c", serie); chart.removeLegend(); chart.setAntiAlias(false); XYPlot plot = chart.getXYPlot(); AxisSpace space = new AxisSpace(); space.setLeft(GRAPHIC_SPACE.getLeft() - 8); plot.setFixedRangeAxisSpace(space); org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis(); String selection = scaling.getSelection().getActionCommand(); switch (selection) { case "max": { yAxis.setRange(_presenter.getMinMaxRangeEnergy()); } break; case "mean": { yAxis.setRange(_presenter.getMeanRangeEnergy()); } break; case "auto": break; } org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis(); double start = 0; double max = _presenter.getFullData().length / Double.valueOf(spinnerDiscretization.getValue().toString()); xAxis.setRange(start, max); ChartPanel chartPanel = new ChartPanel(chart); drawFullGraphOfEnergy(chartPanel); }
From source file:ru.spbspu.viewer.DataView.java
/** * ? ? /*from ww w.j a v a2 s .c o m*/ */ public void buildEnergyGraph() { CategoryTableXYDataset serie = new CategoryTableXYDataset(); serie.setNotify(false); double step = 1.0 / getDiscretization(); double startPosition = step * getFramePosition(); double[] data = _presenter.getFrameEnergy(getFramePosition(), getFrameWidth(), getWindowWidth()); for (int i = 0; i < data.length; i++) { serie.add(startPosition, data[i], ""); startPosition += step * getFrameWidth() / (data.length - 1); } JFreeChart chart = ChartFactory.createXYLineChart("", "t,c", "", serie); chart.removeLegend(); chart.setAntiAlias(false); XYPlot plot = chart.getXYPlot(); org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis(); String selection = scaling.getSelection().getActionCommand(); switch (selection) { case "max": { yAxis.setRange(_presenter.getMinMaxRangeEnergy()); } break; case "mean": { yAxis.setRange(_presenter.getMeanRangeEnergy()); } break; case "auto": break; } plot.setFixedRangeAxisSpace(GRAPHIC_SPACE); org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis(); double start = getFramePosition() * 1.0 / getDiscretization(); double max = start + getFrameWidth() * 1.0 / getDiscretization(); xAxis.setRange(start, max); // yAxis.setRange(3.99, 4.01); ChartPanel chartPanel = new ChartPanel(chart); drawGraphOfEnergy(chartPanel); }
From source file:org.ramadda.data.services.PointFormHandler.java
/** * _more_//from w w w . j a va2 s. c o m * * @param request _more_ * @param pointEntry _more_ * @param plotInfo _more_ * * @return _more_ * * @throws Exception _more_ */ public BufferedImage makeTimeseriesImage(Request request, PointEntry pointEntry, final PlotInfo plotInfo) throws Exception { Entry entry = pointEntry.getEntry(); int width = TIMESERIES_WIDTH; int height = TIMESERIES_HEIGHT; long numRecords = pointEntry.getNumRecords(); final int numPointsToPlot = request.get(ARG_NUMPOINTS, TIMESERIES_POINTS); final int[] cnt = { 0 }; final List<TimeSeries> series = new ArrayList<TimeSeries>(); final List<RecordField> tmpFields = pointEntry.getRecordFile().getChartableFields(); final List<RecordField> fields = new ArrayList<RecordField>(); if (request.get(ARG_CHART_SHOW + FIELD_ALTITUDE, false)) { fields.add(new RecordField(FIELD_ALTITUDE, LABEL_ALTITUDE, "", -1, UNIT_M)); } for (RecordField attr : tmpFields) { if (request.get(ARG_CHART_SHOW + attr.getName(), false)) { fields.add(attr); } } if ((fields.size() == 0) && (tmpFields.size() > 0)) { fields.add(tmpFields.get(0)); request.put(ARG_CHART_SHOW + tmpFields.get(0).getName(), "true"); } for (RecordField attr : fields) { series.add(new TimeSeries(attr.getLabel())); } RecordVisitor visitor = new BridgeRecordVisitor(getOutputHandler()) { public boolean doVisitRecord(RecordFile file, VisitInfo visitInfo, Record record) { PointRecord pointRecord = (PointRecord) record; for (int fieldCnt = 0; fieldCnt < fields.size(); fieldCnt++) { RecordField field = fields.get(fieldCnt); double value; //Check for altitude if (field.getParamId() < 0) { value = pointRecord.getAltitude(); } else { value = record.getValue(field.getParamId()); } long time = record.getRecordTime(); series.get(fieldCnt).add(new FixedMillisecond(time), value); } plotInfo.setIndex(pointRecord.index); cnt[0]++; return true; } }; long t1 = System.currentTimeMillis(); int skip = (int) (numRecords / numPointsToPlot); getRecordJobManager().visitSequential(request, pointEntry, visitor, new VisitInfo(skip)); long t2 = System.currentTimeMillis(); JFreeChart chart = createTimeseriesChart(request, entry, new TimeSeriesCollection(), null); long t3 = System.currentTimeMillis(); XYPlot plot = (XYPlot) chart.getPlot(); int lineCnt = 0; int[] colorCnt = { 0 }; int numberOfAxisLegends = 0; Hashtable<String, double[]> valueRanges = new Hashtable<String, double[]>(); for (int extraCnt = 0; extraCnt < series.size(); extraCnt++) { TimeSeries timeSeries = series.get(extraCnt); RecordField field = fields.get(extraCnt); String unit = field.getUnit(); if ((unit != null) && (unit.length() == 0)) { unit = null; } if (unit == null) { unit = extraCnt + ""; } if (unit == null) { continue; } double max = timeSeries.getMaxY(); double min = timeSeries.getMinY(); double[] range = valueRanges.get(unit); if (range == null) { range = new double[] { min, max }; valueRanges.put(unit, range); } else { range[0] = Math.min(range[0], min); range[1] = Math.max(range[1], max); } } Hashtable<String, NumberAxis> seenAxis = new Hashtable<String, NumberAxis>(); for (int extraCnt = 0; extraCnt < series.size(); extraCnt++) { TimeSeries timeSeries = series.get(extraCnt); RecordField field = fields.get(extraCnt); String unit = field.getUnit(); if ((unit != null) && (unit.length() == 0)) { unit = null; } TimeSeriesCollection dataset2 = new TimeSeriesCollection(); dataset2.addSeries(timeSeries); NumberAxis axis = new NumberAxis(field.getLabel()); numberOfAxisLegends++; if (unit != null) { double[] range = valueRanges.get(unit); axis.setRange(range[0], range[1]); NumberAxis seenOne = seenAxis.get(unit); if (seenOne == null) { seenAxis.put(unit, axis); } else { seenOne.setLabel(seenOne.getLabel() + "/" + field.getLabel()); axis.setVisible(false); numberOfAxisLegends--; } } else { axis.setAutoRange(true); axis.setAutoRangeIncludesZero(true); } plot.setRangeAxis(lineCnt, axis); plot.setDataset(lineCnt, dataset2); plot.mapDatasetToRangeAxis(lineCnt, lineCnt); plot.setRangeAxisLocation(lineCnt, AxisLocation.BOTTOM_OR_RIGHT); StandardXYItemRenderer renderer = new MyStandardXYItemRenderer(plotInfo); renderer.setSeriesPaint(0, getColor(request, ARG_CHART_COLOR + field.getName(), colorCnt)); plot.setRenderer(lineCnt, renderer); lineCnt++; } AxisSpace axisSpace = new AxisSpace(); axisSpace.setRight(TIMESERIES_AXIS_WIDTHPER * numberOfAxisLegends); plot.setFixedRangeAxisSpace(axisSpace); long t4 = System.currentTimeMillis(); BufferedImage newImage = chart.createBufferedImage(width + (numberOfAxisLegends * TIMESERIES_AXIS_WIDTHPER), height); long t5 = System.currentTimeMillis(); // System.err.println("Time series cnt:" + cnt[0] + " " + (t2 - t1) + " " + (t3 - t2) + " " + (t4 - t3) + " " + (t5 - t4)); return newImage; }