List of usage examples for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT
AxisLocation BOTTOM_OR_RIGHT
To view the source code for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT.
Click Source Link
From source file:org.ramadda.data.services.PointFormHandler.java
/** * _more_// ww w. j av a 2 s. com * * @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; }
From source file:org.ramadda.geodata.cdmdata.PointDatabaseTypeHandler.java
/** * _more_// w w w . j a va2 s . co m * * @param request _more_ * @param entry _more_ * @param columnsToUse _more_ * @param list _more_ * * @return _more_ * * @throws Exception _more_ */ private Result makeSearchResultsTimeSeries(Request request, Entry entry, List<PointDataMetadata> columnsToUse, List<PointData> list) throws Exception { StringBuffer sb = new StringBuffer(); sb.append(getHeader(request, entry)); sb.append(header(msg("Point Data Search Results"))); if (list.size() == 0) { sb.append(msg("No results found")); return new Result("Point Search Results", sb); } TimeSeriesCollection dummy = new TimeSeriesCollection(); JFreeChart chart = createChart(request, entry, dummy); XYPlot xyPlot = (XYPlot) chart.getPlot(); Hashtable<String, MyTimeSeries> seriesMap = new Hashtable<String, MyTimeSeries>(); List<MyTimeSeries> allSeries = new ArrayList<MyTimeSeries>(); int paramCount = 0; int colorCount = 0; boolean axisLeft = true; Hashtable<String, List<ValueAxis>> axisMap = new Hashtable<String, List<ValueAxis>>(); Hashtable<String, double[]> rangeMap = new Hashtable<String, double[]>(); List<String> units = new ArrayList<String>(); long t1 = System.currentTimeMillis(); for (PointData pointData : list) { for (PointDataMetadata pdm : columnsToUse) { if (!pdm.isNumeric()) { continue; } double value = ((Double) pointData.getValue(pdm)).doubleValue(); if (value != value) { continue; } List<ValueAxis> axises = null; double[] range = null; if (pdm.hasUnit()) { axises = axisMap.get(pdm.unit); range = rangeMap.get(pdm.unit); if (axises == null) { axises = new ArrayList<ValueAxis>(); range = new double[] { value, value }; rangeMap.put(pdm.unit, range); axisMap.put(pdm.unit, axises); units.add(pdm.unit); } range[0] = Math.min(range[0], value); range[1] = Math.max(range[1], value); } MyTimeSeries series = seriesMap.get(pdm.getColumnName()); if (series == null) { paramCount++; TimeSeriesCollection dataset = new TimeSeriesCollection(); series = new MyTimeSeries(pdm.formatName(), FixedMillisecond.class); allSeries.add(series); ValueAxis rangeAxis = new NumberAxis(pdm.formatName() + " " + pdm.formatUnit()); if (axises != null) { axises.add(rangeAxis); } XYItemRenderer renderer = new XYAreaRenderer(XYAreaRenderer.LINES); if (colorCount >= HtmlUtils.COLORS.length) { colorCount = 0; } renderer.setSeriesPaint(0, HtmlUtils.COLORS[colorCount]); colorCount++; xyPlot.setRenderer(paramCount, renderer); xyPlot.setRangeAxis(paramCount, rangeAxis, false); AxisLocation side = (axisLeft ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT); axisLeft = !axisLeft; xyPlot.setRangeAxisLocation(paramCount, side); dataset.setDomainIsPointsInTime(true); dataset.addSeries(series); seriesMap.put(pdm.getColumnName(), series); xyPlot.setDataset(paramCount, dataset); xyPlot.mapDatasetToRangeAxis(paramCount, paramCount); } //series.addOrUpdate(new FixedMillisecond(pointData.date),value); TimeSeriesDataItem item = new TimeSeriesDataItem(new FixedMillisecond(pointData.date), value); series.addItem(item); } } for (MyTimeSeries timeSeries : allSeries) { timeSeries.finish(); } for (String unit : units) { List<ValueAxis> axises = axisMap.get(unit); double[] range = rangeMap.get(unit); for (ValueAxis rangeAxis : axises) { rangeAxis.setRange(new org.jfree.data.Range(range[0], range[1])); } } long t2 = System.currentTimeMillis(); BufferedImage newImage = chart.createBufferedImage(request.get(ARG_POINT_IMAGE_WIDTH, 1000), request.get(ARG_POINT_IMAGE_HEIGHT, 400)); long t3 = System.currentTimeMillis(); //System.err.println("timeseries image time:" + (t2 - t1) + " " // + (t3 - t2)); File file = getStorageManager().getTmpFile(request, "point.png"); ImageUtils.writeImageToFile(newImage, file); InputStream is = getStorageManager().getFileInputStream(file); Result result = new Result("", is, "image/png"); return result; }
From source file:org.ramadda.geodata.cdmdata.CdmDataOutputHandler.java
/** * Output the timeseries image/*from w w w . java2 s .c o m*/ * * @param request the request * @param entry the entry * @param f the file * * @return the image * * @throws Exception problem creating image */ private Result outputTimeSeriesImage(Request request, Entry entry, File f) throws Exception { StringBuffer sb = new StringBuffer(); //sb.append(getHeader(request, entry)); sb.append(header(msg("Chart"))); TimeSeriesCollection dummy = new TimeSeriesCollection(); JFreeChart chart = createChart(request, entry, dummy); XYPlot xyPlot = (XYPlot) chart.getPlot(); Hashtable<String, MyTimeSeries> seriesMap = new Hashtable<String, MyTimeSeries>(); List<MyTimeSeries> allSeries = new ArrayList<MyTimeSeries>(); int paramCount = 0; int colorCount = 0; boolean axisLeft = true; Hashtable<String, List<ValueAxis>> axisMap = new Hashtable<String, List<ValueAxis>>(); Hashtable<String, double[]> rangeMap = new Hashtable<String, double[]>(); List<String> units = new ArrayList<String>(); List<String> paramUnits = new ArrayList<String>(); List<String> paramNames = new ArrayList<String>(); long t1 = System.currentTimeMillis(); String contents = IOUtil.readContents(getStorageManager().getFileInputStream(f)); List<String> lines = StringUtil.split(contents, "\n", true, true); String header = lines.get(0); String[] headerToks = header.split(","); for (int i = 0; i < headerToks.length; i++) { paramNames.add(getParamName(headerToks[i])); paramUnits.add(getUnitFromName(headerToks[i])); } boolean hasLevel = paramNames.get(3).equals("vertCoord"); boolean readHeader = false; for (String line : lines) { if (!readHeader) { readHeader = true; continue; } String[] lineTokes = line.split(","); Date date = DateUtil.parse(lineTokes[0]); int startIdx = hasLevel ? 4 : 3; for (int i = startIdx; i < lineTokes.length; i++) { double value = Double.parseDouble(lineTokes[i]); if (value != value) { continue; } List<ValueAxis> axises = null; double[] range = null; String u = paramUnits.get(i); String paramName = paramNames.get(i); String formatName = paramName.replaceAll("_", " "); String formatUnit = ((u == null) || (u.length() == 0)) ? "" : "[" + u + "]"; if (u != null) { axises = axisMap.get(u); range = rangeMap.get(u); if (axises == null) { axises = new ArrayList<ValueAxis>(); range = new double[] { value, value }; rangeMap.put(u, range); axisMap.put(u, axises); units.add(u); } range[0] = Math.min(range[0], value); range[1] = Math.max(range[1], value); } MyTimeSeries series = seriesMap.get(paramName); if (series == null) { paramCount++; TimeSeriesCollection dataset = new TimeSeriesCollection(); series = new MyTimeSeries(formatName, FixedMillisecond.class); allSeries.add(series); ValueAxis rangeAxis = new NumberAxis(formatName + " " + formatUnit); if (axises != null) { axises.add(rangeAxis); } XYItemRenderer renderer = new XYAreaRenderer(XYAreaRenderer.LINES); if (colorCount >= GuiUtils.COLORS.length) { colorCount = 0; } renderer.setSeriesPaint(0, GuiUtils.COLORS[colorCount]); colorCount++; xyPlot.setRenderer(paramCount, renderer); xyPlot.setRangeAxis(paramCount, rangeAxis, false); AxisLocation side = (axisLeft ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT); axisLeft = !axisLeft; xyPlot.setRangeAxisLocation(paramCount, side); dataset.setDomainIsPointsInTime(true); dataset.addSeries(series); seriesMap.put(paramNames.get(i), series); xyPlot.setDataset(paramCount, dataset); xyPlot.mapDatasetToRangeAxis(paramCount, paramCount); } //series.addOrUpdate(new FixedMillisecond(pointData.date),value); TimeSeriesDataItem item = new TimeSeriesDataItem(new FixedMillisecond(date), value); series.addItem(item); } } for (MyTimeSeries timeSeries : allSeries) { timeSeries.finish(); } for (String unit : units) { List<ValueAxis> axises = axisMap.get(unit); double[] range = rangeMap.get(unit); for (ValueAxis rangeAxis : axises) { rangeAxis.setRange(new org.jfree.data.Range(range[0], range[1])); } } long t2 = System.currentTimeMillis(); BufferedImage newImage = chart.createBufferedImage(request.get(ARG_IMAGE_WIDTH, 1000), request.get(ARG_IMAGE_HEIGHT, 400)); long t3 = System.currentTimeMillis(); //System.err.println("timeseries image time:" + (t2 - t1) + " " // + (t3 - t2)); File file = getStorageManager().getTmpFile(request, "point.png"); ImageUtils.writeImageToFile(newImage, file); InputStream is = getStorageManager().getFileInputStream(file); Result result = new Result("", is, "image/png"); return result; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * Specifies the axis location.//from w w w. java 2 s . co m * It has to be overridden for child themes with another default axis location */ protected AxisLocation getChartAxisLocation(JRChartAxis chartAxis) { if (chartAxis.getPositionValue() != null) { switch (chartAxis.getPositionValue()) { case RIGHT_OR_BOTTOM: return AxisLocation.BOTTOM_OR_RIGHT; default: return AxisLocation.TOP_OR_LEFT; } } else { return (AxisLocation) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_LOCATION); } }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * Specifies the axis location.//from www .jav a 2 s .co m * It has to be overridden for child themes with another default axis location */ protected AxisLocation getChartAxisLocation(JRChartAxis chartAxis) { return chartAxis.getPositionValue() != null && chartAxis.getPositionValue() == AxisPositionEnum.RIGHT_OR_BOTTOM ? AxisLocation.BOTTOM_OR_RIGHT : AxisLocation.TOP_OR_LEFT; }