Example usage for org.jfree.chart.axis NumberAxis setRange

List of usage examples for org.jfree.chart.axis NumberAxis setRange

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setRange.

Prototype

public void setRange(double lower, double upper) 

Source Link

Document

Sets the range for the axis and sends a change event to all registered listeners.

Usage

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
 * Returns a XYPlot for Battery Info/*from   ww w  . ja  v a2 s .  com*/
 * 
 * @return XYPlot.
 */
private static XYPlot createBatteryPlot() {

    // Set up renderer
    StandardXYItemRenderer batteryRenderer = new StandardXYItemRenderer(
            StandardXYItemRenderer.SHAPES_AND_LINES);
    batteryRenderer.setAutoPopulateSeriesShape(false);
    batteryRenderer.setBaseShape(DEFAULT_POINT_SHAPE);
    batteryRenderer.setSeriesPaint(0, Color.red);

    // Normalize the throughput axis so that it represents max value
    NumberAxis axis = new NumberAxis();
    axis.setVisible(false);
    axis.setAutoRange(false);
    axis.setRange(0, 110);

    // Create plot
    XYPlot batteryPlot = new XYPlot(null, null, axis, batteryRenderer);
    batteryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    batteryPlot.getRangeAxis().setVisible(false);

    return batteryPlot;

}

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
* Returns a XYPlot for Alarm triggering info
* 
* @return XYPlot.//from   w w w .j a  va2 s .c om
*/
private static XYPlot createAlarmPlot() {

    // Create renderer
    XYBarRenderer alarmRenderer = new XYBarRenderer();
    alarmRenderer.setDrawBarOutline(false);
    alarmRenderer.setUseYInterval(true);
    alarmRenderer.setBasePaint(Color.gray);
    alarmRenderer.setAutoPopulateSeriesPaint(false);
    alarmRenderer.setShadowVisible(false);
    alarmRenderer.setGradientPaintTransformer(null);
    alarmRenderer.setBarPainter(new StandardXYBarPainter());

    // Normalize the throughput axis so that it represents max value
    NumberAxis axis = new NumberAxis();
    axis.setVisible(false);
    axis.setAutoRange(false);
    axis.setRange(0, 1);

    // Create result plot
    XYPlot alarmPlot = new XYPlot(null, null, axis, alarmRenderer);
    alarmPlot.getRangeAxis().setVisible(false);
    return alarmPlot;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

@Override
public void resetAxes(final IScope scope) {
    NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis();

    if (getX_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(domainAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((XYPlot) this.chart.getPlot()).setDomainAxis(logAxis);
        domainAxis = logAxis;//from  w w w.j a  v  a2s. c  o m
    }
    if (getY_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((XYPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;
    }
    if (!usexrangeinterval && !usexrangeminmax) {
        //         domainAxis.setAutoRangeMinimumSize(0.5);
        //         domainAxis.setAutoRange(true);
    }

    if (this.usexrangeinterval) {
        domainAxis.setFixedAutoRange(xrangeinterval);
        domainAxis.setAutoRangeMinimumSize(xrangeinterval);
        domainAxis.setAutoRange(true);
    }
    if (this.usexrangeminmax) {
        domainAxis.setRange(xrangemin, xrangemax);
    }

    if (!useyrangeinterval && !useyrangeminmax) {
        //      rangeAxis.setAutoRangeMinimumSize(0.5);
        //      rangeAxis.setAutoRange(true);
    }

    if (this.useyrangeinterval) {
        rangeAxis.setFixedAutoRange(yrangeinterval);
        rangeAxis.setAutoRangeMinimumSize(yrangeinterval);
        rangeAxis.setAutoRange(true);
    }
    if (this.useyrangeminmax) {
        rangeAxis.setRange(yrangemin, yrangemax);
    }
    if (this.series_label_position.equals("none")) {
        if ((this.chart).getLegend() != null)
            (this.chart).getLegend().setVisible(false);
    }
    if (!this.getXTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(false);

    }
    if (!this.getYTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false);

    }

}

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

/**
 * _more_/*from  w  w w  .  jav 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.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java

private void updateChart(SimpleFeatureCollection features, String xField, String yField) {
    // 1. Create a single plot containing both the scatter and line
    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);//  w  ww  . j  a  v a 2s  .com
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // 2. Setup Scatter plot
    // Create the scatter data, renderer, and axis
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];
    NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator();

    XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only
    plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
    plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot
    plotRenderer.setBaseToolTipGenerator(plotToolTip);

    // Set the scatter data, renderer, and axis into plot
    plot.setDataset(0, getScatterPlotData(features, xField, yField));

    xPlotAxis.setAutoRangeIncludesZero(false);
    xPlotAxis.setAutoRange(false);
    double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX();
    double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX();
    double gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX());
    } else {
        xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap);
    }

    yPlotAxis.setAutoRangeIncludesZero(false);
    yPlotAxis.setAutoRange(false);
    differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY();
    differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY();
    gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY());
    } else {
        yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap);
    }

    plot.setRenderer(0, plotRenderer);
    plot.setDomainAxis(0, xPlotAxis);
    plot.setRangeAxis(0, yPlotAxis);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY);

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);

    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    // AverageY
    XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$
    horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY());
    horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY());
    lineDataset.addSeries(horizontal);

    // AverageX
    XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound());
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound());
    lineDataset.addSeries(vertical);

    // Degree
    XYSeries degree = new XYSeries("Deegree"); //$NON-NLS-1$
    degree.add(xPlotAxis.getRange().getLowerBound(), yPlotAxis.getRange().getLowerBound());
    degree.add(xPlotAxis.getRange().getUpperBound(), yPlotAxis.getRange().getUpperBound());
    lineDataset.addSeries(degree);

    plot.setDataset(1, lineDataset);
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    // 4. Setup Selection
    NumberAxis xSelectionAxis = new NumberAxis(EMPTY);
    xSelectionAxis.setTickMarksVisible(false);
    xSelectionAxis.setTickLabelsVisible(false);

    NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
    ySelectionAxis.setTickMarksVisible(false);
    ySelectionAxis.setTickLabelsVisible(false);

    XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only
    selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6));
    selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot

    plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY)));
    plot.setRenderer(2, selectionRenderer);
    plot.setDomainAxis(2, xSelectionAxis);
    plot.setRangeAxis(2, ySelectionAxis);

    // Map the scatter to the second Domain and second Range
    plot.mapDatasetToDomainAxis(2, 0);
    plot.mapDatasetToRangeAxis(2, 0);

    // 5. Finally, Create the chart with the plot and a legend
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:gov.nih.nci.cma.web.graphing.CMAPrincipalComponentAnalysisPlot.java

private void createChart() {

    String xLabel = component1.toString();
    String yLabel = component2.toString();

    pcaChart = ChartFactory.createScatterPlot("Principal Component Analysis", xLabel, yLabel, null,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) pcaChart.getPlot();

    buildLegend();//from ww w. j av a2  s .  com

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    //        XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5));
    //
    //        plot.addAnnotation(annotation);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.
    DataRange component1Range = getDataRange(dataPoints, PCAcomponent.PC1);
    DataRange component2Range = getDataRange(dataPoints, PCAcomponent.PC2);
    DataRange component3Range = getDataRange(dataPoints, PCAcomponent.PC3);

    Double pc1AbsMax = Math.max(Math.abs(component1Range.getMaxRange()),
            Math.abs(component1Range.getMinRange()));
    Double pc2AbsMax = Math.max(Math.abs(component2Range.getMaxRange()),
            Math.abs(component2Range.getMinRange()));
    Double pc3AbsMax = Math.max(Math.abs(component3Range.getMaxRange()),
            Math.abs(component3Range.getMinRange()));

    Double maxAbsVal = Math.max(pc1AbsMax, pc2AbsMax);

    maxAbsVal = Math.max(maxAbsVal, pc3AbsMax);

    //maxAbsVal = Math.max(100.0, maxAbsVal);

    domainAxis.setAutoRangeIncludesZero(false);

    double tickUnit = 25.0;

    if (maxAbsVal <= 50.0 && maxAbsVal >= 25.0) {
        tickUnit = 10.0; //5.0;
    } else if (maxAbsVal <= 25.0) {
        tickUnit = 5.0;
    }

    domainAxis.setTickUnit(new NumberTickUnit(tickUnit));
    rangeAxis.setTickUnit(new NumberTickUnit(tickUnit));

    double glyphScaleFactor = (maxAbsVal * 2.0) / 600.0; //assuming 600 pixels for the graph

    double adjAbsVal = Math.ceil(maxAbsVal + (glyphScaleFactor * 8.0));

    //domainAxis.setRange(-maxAbsVal, maxAbsVal);
    domainAxis.setRange(-adjAbsVal, adjAbsVal);

    //rangeAxis.setRange(-maxAbsVal, maxAbsVal);
    rangeAxis.setRange(-adjAbsVal, adjAbsVal);

    createGlyphsAndAddToPlot(plot); //, glyphScaleFactor);

    // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
    //try and match the UI e9e9e9
    Paint p = new Color(233, 233, 233);

    pcaChart.setBackgroundPaint(p);
}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java

private void createChart() {

    String xLabel = component1.toString();
    String yLabel = component2.toString();

    pcaChart = ChartFactory.createScatterPlot("Principal Component Analysis", xLabel, yLabel, null,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) pcaChart.getPlot();

    buildLegend();/*from   w  w  w. ja v a2  s . co m*/

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    //        XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5));
    //           
    //        plot.addAnnotation(annotation);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.
    DataRange component1Range = getDataRange(dataPoints, PCAcomponent.PC1);
    DataRange component2Range = getDataRange(dataPoints, PCAcomponent.PC2);
    DataRange component3Range = getDataRange(dataPoints, PCAcomponent.PC3);

    Double pc1AbsMax = Math.max(Math.abs(component1Range.getMaxRange()),
            Math.abs(component1Range.getMinRange()));
    Double pc2AbsMax = Math.max(Math.abs(component2Range.getMaxRange()),
            Math.abs(component2Range.getMinRange()));
    Double pc3AbsMax = Math.max(Math.abs(component3Range.getMaxRange()),
            Math.abs(component3Range.getMinRange()));

    Double maxAbsVal = Math.max(pc1AbsMax, pc2AbsMax);

    maxAbsVal = Math.max(maxAbsVal, pc3AbsMax);

    //maxAbsVal = Math.max(100.0, maxAbsVal);

    domainAxis.setAutoRangeIncludesZero(false);

    double tickUnit = 25.0;

    if (maxAbsVal <= 25.0) {
        tickUnit = 5.0;
    } else if (maxAbsVal <= 50.0) {
        tickUnit = 10.0;
    }

    domainAxis.setTickUnit(new NumberTickUnit(tickUnit));
    rangeAxis.setTickUnit(new NumberTickUnit(tickUnit));

    double glyphScaleFactor = (maxAbsVal * 2.0) / 600.0; //assuming 600 pixels for the graph

    double adjAbsVal = Math.ceil(maxAbsVal + (glyphScaleFactor * 8.0));

    //domainAxis.setRange(-maxAbsVal, maxAbsVal);
    domainAxis.setRange(-adjAbsVal, adjAbsVal);

    //rangeAxis.setRange(-maxAbsVal, maxAbsVal);
    rangeAxis.setRange(-adjAbsVal, adjAbsVal);

    createGlyphsAndAddToPlot(plot, glyphScaleFactor);

    // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
    //try and match the UI e9e9e9
    Paint p = new Color(233, 233, 233);

    pcaChart.setBackgroundPaint(p);
}

From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java

private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) {
    // 1. Create a single plot containing both the scatter and line
    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);// www . j  a  v a2s  .com
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setForegroundAlpha(0.75f);

    // 2. Setup Scatter plot
    // Create the bubble chart data, renderer, and axis
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];
    NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot
    plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator());
    plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    plotRenderer
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));

    // Set the bubble chart data, renderer, and axis into plot
    plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField));

    xPlotAxis.setAutoRangeIncludesZero(false);
    xPlotAxis.setAutoRange(false);
    double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX();
    double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX();
    double gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX());
    } else {
        xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap);
    }

    yPlotAxis.setAutoRangeIncludesZero(false);
    yPlotAxis.setAutoRange(false);
    differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY();
    differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY();
    gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY());
    } else {
        yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap);
    }

    plot.setRenderer(0, plotRenderer);
    plot.setDomainAxis(0, xPlotAxis);
    plot.setRangeAxis(0, yPlotAxis);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY);

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);

    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    // AverageY
    XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$
    horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY());
    horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY());
    lineDataset.addSeries(horizontal);

    // AverageX
    XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound());
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound());
    lineDataset.addSeries(vertical);

    plot.setDataset(1, lineDataset);
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    // 4. Setup Selection
    NumberAxis xSelectionAxis = new NumberAxis(EMPTY);
    xSelectionAxis.setTickMarksVisible(false);
    xSelectionAxis.setTickLabelsVisible(false);

    NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
    ySelectionAxis.setTickMarksVisible(false);
    ySelectionAxis.setTickLabelsVisible(false);

    XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot
    selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED);

    plot.setDataset(2, new DefaultXYZDataset2());
    plot.setRenderer(2, selectionRenderer);
    plot.setDomainAxis(2, xSelectionAxis);
    plot.setRangeAxis(2, ySelectionAxis);

    // Map the scatter to the second Domain and second Range
    plot.mapDatasetToDomainAxis(2, 0);
    plot.mapDatasetToRangeAxis(2, 0);

    // 5. Finally, Create the chart with the plot and a legend
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:msi.gama.outputs.layers.ChartLayerStatement.java

private void createBars(final IScope scope) {
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer renderer = new CustomRenderer();
    plot.setRenderer(renderer);//from w  w  w  .j av  a 2  s.  c  o m

    dataset = new DefaultCategoryDataset();
    int i = 0;
    for (final ChartData e : datas) {
        // String legend = e.getName();
        // ((DefaultCategoryDataset) dataset).setValue(0d, new Integer(0), legend/* , legend */);

        final String legend = e.getName();
        if (!CategoryItemRenderer.class.isInstance(e.getRenderer())) {
            e.renderer = new CustomRenderer();
        }
        plot.setRenderer(i, (CategoryItemRenderer) e.getRenderer(), false);
        final Color c = e.getColor();
        plot.getRenderer(i).setSeriesPaint(0, c);
        // plot.setDataset(i, (DefaultCategoryDataset) dataset);
        i++;
        history.append(legend);
        history.append(',');

    }
    if (history.length() > 0) {
        history.deleteCharAt(history.length() - 1);
    }
    history.append(Strings.LN);
    plot.setDataset((DefaultCategoryDataset) dataset);

    chart.removeLegend();
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setTickLabelFont(getTickFont());
    yAxis.setLabelFont(getLabelFont());
    IExpression expr = getFacet(YRANGE);
    IExpression expr2 = getFacet(YTICKUNIT);
    if (expr != null) {
        Object range = expr.value(scope);
        // Double range = Cast.asFloat(scope, expr.value(scope));

        if (range instanceof Number) {
            double r = ((Number) range).doubleValue();
            if (r > 0) {
                yAxis.setFixedAutoRange(r);
                yAxis.setAutoRangeMinimumSize(r);
            }
            // yAxis.setAutoRangeIncludesZero(false);
        } else if (range instanceof GamaPoint) {
            yAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY());
        }
    }
    if (expr2 != null) {
        Object range = expr2.value(scope);
        // Double range = Cast.asFloat(scope, expr.value(scope));

        if (range instanceof Number) {
            double r = ((Number) range).doubleValue();
            if (r > 0) {
                yAxis.setTickUnit(new NumberTickUnit(r));
            }
        }
    }

    final CategoryAxis axis = plot.getDomainAxis();
    Double gap = Cast.asFloat(scope, getFacetValue(scope, IKeyword.GAP, 0.01));
    // ((BarRenderer) plot.getRenderer()).setItemMargin(gap);
    renderer.setMaximumBarWidth(1 - gap);
    axis.setCategoryMargin(gap);
    axis.setUpperMargin(gap);
    axis.setLowerMargin(gap);

}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java

/**
 * Zeichne die eigentliche Grafik Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from   ww w. ja  v  a 2 s  .  c o m
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.07.2012
 * @param dbId
 *          dbid in Tabelle D_TABLE_DIVEDETAIL
 * @param device
 */
private void makeGraphForLog(int dbId, String device) {
    Vector<Integer[]> diveList;
    Vector<String> diluents;
    int[] headData;
    XYPlot thePlot;
    JFreeChart logChart;
    int min, sec;
    // das alte Zeug entsorgen
    releaseGraph();
    //
    // Daten eines TG lesen
    //
    lg.debug("read dive log from DB...");
    diveList = databaseUtil.getDiveDataFromIdLog(dbId);
    if (diveList == null || diveList.isEmpty()) {
        return;
    }
    //
    // verwendete Diluents finden
    //
    diluents = getDiluentNamesFromDive(diveList);
    // Anzeigen
    String diluentString = StringUtils.join(diluents, ", ");
    diluentLabel.setText(
            String.format(LangStrings.getString("spx42LogGraphPanel.diluentLabel.text"), diluentString));
    lg.debug(diluents);
    //
    // Labels fr Tachgangseckdaten fllen
    //
    headData = databaseUtil.getHeadDiveDataFromIdLog(dbId);
    notesLabel.setText(databaseUtil.getNotesForIdLog(dbId));
    showingUnitSystem = SpxPcloggerProgramConfig.unitsProperty;
    savedUnitSystem = headData[6];
    // jetzt die Strings fr Masseinheiten holen
    String[] labels = getUnitsLabel(showingUnitSystem, savedUnitSystem);
    depthUnitName = labels[0];
    tempUnitName = labels[1];
    pressureUnitName = labels[2];
    //
    // entscheide ob etwas umgerechnet werden sollte
    //
    if (showingUnitSystem == savedUnitSystem || showingUnitSystem == ProjectConst.UNITS_DEFAULT) {
        // nein, alles schick
        maxDepthValueLabel.setText(String.format(maxDepthLabelString, (headData[3] / 10.0), depthUnitName));
        coldestTempValueLabel.setText(String.format(coldestLabelString, (headData[2] / 10.0), tempUnitName));
    } else {
        // umrechnen!
        if (showingUnitSystem == ProjectConst.UNITS_IMPERIAL) {
            // metrisch-> imperial konvertieren
            // 1 foot == 30,48 cm == 0.3048 Meter
            maxDepthValueLabel
                    .setText(String.format(maxDepthLabelString, (headData[3] / 10.0) / 0.3048, depthUnitName));
            // t F = 5?9 (t  32) C
            coldestTempValueLabel.setText(
                    String.format(coldestLabelString, (5.0 / 9.0) * ((headData[2] / 10.0) - 32), tempUnitName));
        } else {
            maxDepthValueLabel
                    .setText(String.format(maxDepthLabelString, (headData[3] / 10.0) * 0.3048, depthUnitName));
            // t C = (9?5 t + 32) F
            coldestTempValueLabel.setText(
                    String.format(coldestLabelString, ((9.0 / 5.0) * (headData[2] / 10.0)) + 32, tempUnitName));
        }
    }
    min = headData[5] / 60;
    sec = headData[5] % 60;
    diveLenValueLabel.setText(String.format(diveLenLabelString, min, sec, "min"));
    //
    // einen Plot machen (Grundlage des Diagramms)
    //
    lg.debug("create graph...");
    thePlot = new XYPlot();
    //
    // Eigenschaften definieren
    //
    thePlot.setBackgroundPaint(Color.lightGray);
    thePlot.setDomainGridlinesVisible(true);
    thePlot.setDomainGridlinePaint(Color.white);
    thePlot.setRangeGridlinesVisible(true);
    thePlot.setRangeGridlinePaint(Color.white);
    thePlot.setDomainPannable(true);
    thePlot.setRangePannable(false);
    //
    // ein Chart zur Anzeige in einem Panel erzeugen
    //
    logChart = new JFreeChart(LangStrings.getString("spx42LogGraphPanel.graph.chartTitle"), thePlot);
    logChart.setAntiAlias(true);
    logChart.addSubtitle(new TextTitle(LangStrings.getString("spx42LogGraphPanel.graph.chartSubTitle")));
    // ein Thema zufgen, damit ich eigene Farben einbauen kann
    ChartUtilities.applyCurrentTheme(logChart);
    //
    // ein Diagramm-Panel erzeugen
    //
    chartPanel = new ChartPanel(logChart);
    chartPanel.setMouseZoomable(true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setRangeZoomable(false);
    chartPanel.setDisplayToolTips(false);
    chartPanel.setZoomTriggerDistance(10);
    add(chartPanel, BorderLayout.CENTER);
    //
    // Datumsachse umformatieren
    //
    final NumberAxis axis = new NumberAxis(LangStrings.getString("spx42LogGraphPanel.graph.dateAxisTitle"));
    MinuteFormatter formatter = new MinuteFormatter(
            LangStrings.getString("spx42LogGraphPanel.graph.dateAxisUnit"));
    axis.setNumberFormatOverride(formatter);
    thePlot.setDomainAxis(axis);
    //
    // Temperatur einfgen
    //
    if (SpxPcloggerProgramConfig.showTemperature) {
        makeTemperatureGraph(diveList, thePlot, labels);
    }
    //
    // Partialdruck einfgen
    // die Achse erst mal machen
    final NumberAxis ppo2Axis = new NumberAxis(
            LangStrings.getString("spx42LogGraphPanel.graph.ppo2AxisTitle") + " " + pressureUnitName);
    final NumberAxis percentAxis = new NumberAxis(LangStrings.getString("spx42LogGraphPanel.graph.inertgas"));
    //
    // wenn eine der Achsen dargesstellt werden muss, dann sollte die Achse auch in der Grafil da sein
    //
    if (SpxPcloggerProgramConfig.showPpo01 || SpxPcloggerProgramConfig.showPpo02
            || SpxPcloggerProgramConfig.showPpo03 || SpxPcloggerProgramConfig.showPpoResult
            || SpxPcloggerProgramConfig.showSetpoint) {
        ppo2Axis.setAutoRangeIncludesZero(false);
        ppo2Axis.setAutoRange(false);
        //
        // wie skaliere ich die Achse?
        //
        if (showingUnitSystem == ProjectConst.UNITS_DEFAULT) {
            // so wie gespeichert
            if (savedUnitSystem == ProjectConst.UNITS_METRIC) {
                ppo2Axis.setRange(0.0, 3.5);
            } else {
                ppo2Axis.setRange(0.0, (3.5 * 14.504));
            }
        } else if (showingUnitSystem == ProjectConst.UNITS_METRIC) {
            ppo2Axis.setRange(0.0, 3.5);
        } else {
            ppo2Axis.setRange(0.0, (3.5 * 14.504));
        }
        ppo2Axis.setLabelPaint(new Color(ProjectConst.GRAPH_PPO2ALL_ACOLOR));
        ppo2Axis.setTickLabelPaint(new Color(ProjectConst.GRAPH_PPO2ALL_ACOLOR));
        thePlot.setRangeAxis(GRAPH_PPO2ALL, ppo2Axis);
    }
    if (SpxPcloggerProgramConfig.showHe || SpxPcloggerProgramConfig.showN2) {
        percentAxis.setAutoRangeIncludesZero(false);
        percentAxis.setAutoRange(false);
        percentAxis.setRange(0.0, 100.0);
        percentAxis.setLabelPaint(new Color(ProjectConst.GRAPH_INNERTGAS_ACOLOR));
        percentAxis.setTickLabelPaint(new Color(ProjectConst.GRAPH_INNERTGAS_ACOLOR));
        thePlot.setRangeAxis(GRAPH_HE, percentAxis);
    }
    //
    // Partialdrcke der einzelnen Sensoren einfgen
    //
    // Sensor 01 anzeigen
    if (SpxPcloggerProgramConfig.showPpo01) {
        makePpoGraph(diveList, thePlot, 1);
    }
    // Sensor 02 anzeigen
    if (SpxPcloggerProgramConfig.showPpo02) {
        makePpoGraph(diveList, thePlot, 2);
    }
    // Sensor 03 anzeigen
    if (SpxPcloggerProgramConfig.showPpo03) {
        makePpoGraph(diveList, thePlot, 3);
    }
    // Resultierenden PPO anzeigen
    if (SpxPcloggerProgramConfig.showPpoResult) {
        makePpoGraph(diveList, thePlot, 0);
        // makePpoResultGraph( diveList, thePlot );
    }
    if (SpxPcloggerProgramConfig.showSetpoint) {
        makeSetpointGraph(diveList, thePlot);
    }
    //
    // Helium und Stickstoffanteil im Gas?
    //
    if (SpxPcloggerProgramConfig.showHe) {
        makeInnertGasGraph(diveList, thePlot, "he");
    }
    if (SpxPcloggerProgramConfig.showN2) {
        makeInnertGasGraph(diveList, thePlot, "n2");
    }
    //
    // die Nullzeit auf Wunsch
    //
    if (SpxPcloggerProgramConfig.showNulltime) {
        makeNulltimeGraph(diveList, thePlot);
    }
    //
    // die Tiefe einfgen
    //
    makeDepthGraph(diveList, thePlot);
    //
    showingDbIdForDiveWasShowing = dbId;
    lg.debug("create graph...OK");
}