Example usage for org.jfree.chart.axis AxisSpace setRight

List of usage examples for org.jfree.chart.axis AxisSpace setRight

Introduction

In this page you can find the example usage for org.jfree.chart.axis AxisSpace setRight.

Prototype

public void setRight(double space) 

Source Link

Document

Sets the space reserved for axes at the right of the plot area.

Usage

From source file:org.jstockchart.plot.TimeseriesPlot.java

private CombinedDomainXYPlot createCombinedXYPlot() {
    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);
    LogicDateAxis logicDateAxis = timeseriesArea.getlogicDateAxis();
    TimeseriesDateAxis dateAxis = new TimeseriesDateAxis(logicDateAxis.getLogicTicks());
    if (timeline != null) {
        dateAxis.setTimeline(timeline);/*from   w  w  w .j  a va  2  s  . co m*/
    }
    dateAxis.setTickLabelFont(axisFont);
    dateAxis.setTickMarkStroke(stroke);
    List<String> hideTick = new ArrayList<String>();
    hideTick.add("10:00");
    hideTick.add("11:00");
    hideTick.add("13:30");
    //hideTick.add("14:30");
    hideTick.add("14:30");
    dateAxis.setHideTickLabel(hideTick);
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    dateAxis.setTickMarksVisible(false);
    Date startTime = DateUtils.createDate(2008, 1, 1, 9, 30, 0);
    Date endTime = DateUtils.createDate(2008, 1, 1, 15, 0, 0);
    dateAxis.setRange(timeseriesArea.getStartDate(), timeseriesArea.getEndDate());
    dateAxis.setAxisLineVisible(false);
    CFXCombinedPlot combinedDomainXYPlot = new CFXCombinedPlot(dateAxis);
    combinedDomainXYPlot.setInsets(new RectangleInsets(5, 2, 4, 2));

    AxisSpace axisSpace = new AxisSpace();
    axisSpace.setBottom(22);
    axisSpace.setLeft(0);
    axisSpace.setRight(0);
    axisSpace.setTop(0);
    combinedDomainXYPlot.setFixedDomainAxisSpace(axisSpace);
    combinedDomainXYPlot.setGap(0);
    combinedDomainXYPlot.setOrientation(timeseriesArea.getOrientation());
    combinedDomainXYPlot.setDomainAxis(dateAxis);
    combinedDomainXYPlot.setDomainAxisLocation(timeseriesArea.getDateAxisLocation());

    if (timeseriesArea.getPriceWeight() <= 0 && timeseriesArea.getVolumeWeight() <= 0) {
        throw new IllegalArgumentException("Illegal weight value: priceWeight="
                + timeseriesArea.getPriceWeight() + ", volumeWeight=" + timeseriesArea.getVolumeWeight());
    }

    if (timeseriesArea.getPriceWeight() > 0) {
        XYPlot pricePlot = createPricePlot();
        combinedDomainXYPlot.add(pricePlot, timeseriesArea.getPriceWeight());
    }

    if (timeseriesArea.getVolumeWeight() > 0) {
        XYPlot volumePlot = createVolumePlot();
        combinedDomainXYPlot.add(volumePlot, timeseriesArea.getVolumeWeight());
    }

    return combinedDomainXYPlot;
}

From source file:org.ramadda.data.services.PointFormHandler.java

/**
 * _more_//from   w ww  .j a  va  2s  .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;
}