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

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

Introduction

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

Prototype

public void setAutoRangeMinimumSize(double size) 

Source Link

Document

Sets the auto range minimum size and sends an AxisChangeEvent to all registered listeners.

Usage

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

@Override
public void resetAxes(final IScope scope) {
    final CategoryPlot pp = (CategoryPlot) this.chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) ((CategoryPlot) this.chart.getPlot()).getRangeAxis();
    if (getY_LogScale(scope)) {
        final LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((CategoryPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;/* www . j  a  v  a  2 s  . c om*/
    }

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

    if (this.useyrangeinterval) {
        rangeAxis.setFixedAutoRange(yrangeinterval);
        rangeAxis.setAutoRangeMinimumSize(yrangeinterval);
        rangeAxis.setAutoRange(true);

    }
    if (this.useyrangeminmax) {
        rangeAxis.setRange(yrangemin, yrangemax);

    }

    resetDomainAxis(scope);

    final CategoryAxis domainAxis = ((CategoryPlot) this.chart.getPlot()).getDomainAxis();

    pp.setDomainGridlinePaint(axesColor);
    pp.setRangeGridlinePaint(axesColor);
    pp.setRangeCrosshairVisible(true);

    pp.getRangeAxis().setAxisLinePaint(axesColor);
    pp.getRangeAxis().setLabelFont(getLabelFont());
    pp.getRangeAxis().setTickLabelFont(getTickFont());
    if (textColor != null) {
        pp.getRangeAxis().setLabelPaint(textColor);
        pp.getRangeAxis().setTickLabelPaint(textColor);
    }
    if (getYTickUnit(scope) > 0) {
        ((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(getYTickUnit(scope)));
    }

    if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) {
        pp.getRangeAxis().setLabel(getYLabel(scope));
    }
    if (this.series_label_position.equals("yaxis")) {
        pp.getRangeAxis().setLabel(this.getChartdataset().getDataSeriesIds(scope).iterator().next());
        chart.getLegend().setVisible(false);
    }

    if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) {
        pp.getDomainAxis().setLabel(getXLabel(scope));
    }

    if (this.useSubAxis) {
        for (final String serieid : chartdataset.getDataSeriesIds(scope)) {
            ((SubCategoryAxis) domainAxis).addSubCategory(serieid);
        }

    }
    if (!this.getYTickLineVisible(scope)) {
        pp.setDomainGridlinesVisible(false);
    }

    if (!this.getYTickLineVisible(scope)) {
        pp.setRangeCrosshairVisible(false);

    }

    if (!this.getYTickValueVisible(scope)) {
        pp.getRangeAxis().setTickMarksVisible(false);
        pp.getRangeAxis().setTickLabelsVisible(false);

    }

}

From source file:Main.Interface_Main.java

private JFreeChart createChartWatt(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Wattage", "Time", "Watts", dataset, false,
            true, false);/*from www. j a  v a2s . c o m*/
    final XYPlot plot = result.getXYPlot();
    XYItemRenderer xyir = plot.getRenderer();
    xyir.setSeriesPaint(0, Color.GREEN);

    plot.setBackgroundPaint(Color.BLACK);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setAutoRange(true);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeMinimumSize(5);
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    return result;
}

From source file:Main.Interface_Main.java

private JFreeChart createChartVolt(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Voltage", "Time", "Volts", dataset, false,
            true, false);/*w ww .  j a  v  a  2 s .c o m*/
    final XYPlot plot = result.getXYPlot();
    XYItemRenderer xyir = plot.getRenderer();
    xyir.setSeriesPaint(0, Color.GREEN);
    xyir.setSeriesPaint(1, Color.RED);
    xyir.setSeriesPaint(2, Color.BLUE);

    plot.setBackgroundPaint(Color.BLACK);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setAutoRange(true);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeMinimumSize(5.2);
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    return result;
}

From source file:Main.Interface_Main.java

/**
 * Sets up the graph for voltage.//w w  w.  j av a  2  s  . c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return Current mA chart.
 */
private JFreeChart createChartCurrent(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Current", "Time", "mA", dataset, false, true,
            false);
    final XYPlot plot = result.getXYPlot();
    XYItemRenderer xyir = plot.getRenderer();
    xyir.setSeriesPaint(0, Color.GREEN);
    xyir.setSeriesPaint(1, Color.RED);
    xyir.setSeriesPaint(2, Color.BLUE);

    plot.setBackgroundPaint(Color.BLACK);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setAutoRange(true);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeMinimumSize(500);
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    return result;
}

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;// w  ww.  j a v  a2  s .c om
    }
    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:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

private boolean writeDetailedFactorAnalysis(ExpressionExperiment ee, OutputStream os) throws Exception {
    SVDValueObject svdo = svdService.getSvdFactorAnalysis(ee.getId());
    if (svdo == null)
        return false;

    if (svdo.getFactors().isEmpty() && svdo.getDates().isEmpty()) {
        return false;
    }/*from  ww  w .  j a  v a  2 s .c  o m*/
    Map<Integer, Map<Long, Double>> factorCorrelations = svdo.getFactorCorrelations();
    // Map<Integer, Map<Long, Double>> factorPvalues = svdo.getFactorPvalues();
    Map<Integer, Double> dateCorrelations = svdo.getDateCorrelations();

    assert ee.getId().equals(svdo.getId());

    ee = expressionExperimentService.thawLite(ee); // need the experimental design
    int maxWidth = 30;
    Map<Long, String> efs = this.getFactorNames(ee, maxWidth);
    Map<Long, ExperimentalFactor> efIdMap = EntityUtils
            .getIdMap(ee.getExperimentalDesign().getExperimentalFactors());
    Collection<Long> continuousFactors = new HashSet<>();
    for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
        boolean isContinous = ExperimentalDesignUtils.isContinuous(ef);
        if (isContinous) {
            continuousFactors.add(ef.getId());
        }
    }

    /*
     * Make plots of the dates vs. PCs, factors vs. PCs.
     */
    int MAX_COMP = 3;

    Map<Long, List<JFreeChart>> charts = new LinkedHashMap<>();
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    /*
     * FACTORS
     */
    String componentShorthand = "PC";
    for (Integer component : factorCorrelations.keySet()) {

        if (component >= MAX_COMP)
            break;
        String xaxisLabel = componentShorthand + (component + 1);

        for (Long efId : factorCorrelations.get(component).keySet()) {

            /*
             * Should not happen.
             */
            if (!efs.containsKey(efId)) {
                log.warn("No experimental factor with id " + efId);
                continue;
            }

            if (!svdo.getFactors().containsKey(efId)) {
                // this should not happen.
                continue;
            }

            boolean isCategorical = !continuousFactors.contains(efId);

            Map<Long, String> categories = new HashMap<>();

            if (isCategorical) {
                this.getCategories(efIdMap, efId, categories);
            }

            if (!charts.containsKey(efId)) {
                charts.put(efId, new ArrayList<JFreeChart>());
            }

            Double a = factorCorrelations.get(component).get(efId);
            String plotname = (efs.get(efId) == null ? "?" : efs.get(efId)) + " " + xaxisLabel; // unique?

            if (a != null && !Double.isNaN(a)) {
                String title = plotname + " " + String.format("%.2f", a);
                List<Double> values = svdo.getFactors().get(efId);
                Double[] eigenGene = this.getEigenGene(svdo, component);
                assert values.size() == eigenGene.length;

                /*
                 * Plot eigengene vs values, add correlation to the plot
                 */
                JFreeChart chart;
                if (isCategorical) {

                    /*
                     * Categorical factor
                     */

                    // use the absolute value of the correlation, since direction is arbitrary.
                    title = plotname + " " + String.format("r=%.2f", Math.abs(a));

                    DefaultMultiValueCategoryDataset dataset = new DefaultMultiValueCategoryDataset();

                    /*
                     * What this code does is organize the factor values by the groups.
                     */
                    Map<String, List<Double>> groupedValues = new TreeMap<>();
                    for (int i = 0; i < values.size(); i++) {
                        Long fvId = values.get(i).longValue();
                        String fvValue = categories.get(fvId);
                        if (fvValue == null) {
                            /*
                             * Problem ...eg gill2006fateinocean id=1748 -- missing values. We just don't plot
                             * anything for this sample.
                             */
                            continue; // is this all we need to do?
                        }
                        if (!groupedValues.containsKey(fvValue)) {
                            groupedValues.put(fvValue, new ArrayList<Double>());
                        }

                        groupedValues.get(fvValue).add(eigenGene[i]);

                        if (log.isDebugEnabled())
                            log.debug(fvValue + " " + values.get(i));
                    }

                    for (String key : groupedValues.keySet()) {
                        dataset.add(groupedValues.get(key), plotname, key);
                    }

                    // don't show the name of the X axis: it's redundant with the title.
                    NumberAxis rangeAxis = new NumberAxis(xaxisLabel);
                    rangeAxis.setAutoRangeIncludesZero(false);
                    // rangeAxis.setAutoRange( false );
                    rangeAxis.setAutoRangeMinimumSize(4.0);
                    // rangeAxis.setRange( new Range( -2, 2 ) );

                    CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis(null), rangeAxis,
                            new ScatterRenderer());
                    plot.setRangeGridlinesVisible(false);
                    plot.setDomainGridlinesVisible(false);

                    chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), plot, false);

                    ScatterRenderer renderer = (ScatterRenderer) plot.getRenderer();
                    float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
                    renderer.setSeriesFillPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
                    renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
                    renderer.setUseOutlinePaint(false);
                    renderer.setUseFillPaint(true);
                    renderer.setBaseFillPaint(Color.white);
                    CategoryAxis domainAxis = plot.getDomainAxis();
                    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                } else {

                    /*
                     * Continuous value factor
                     */

                    DefaultXYDataset series = new DefaultXYDataset();
                    series.addSeries(plotname,
                            new double[][] { ArrayUtils.toPrimitive(values.toArray(new Double[] {})),
                                    ArrayUtils.toPrimitive(eigenGene) });

                    // don't show x-axis label, which would otherwise be efs.get( efId )
                    chart = ChartFactory.createScatterPlot(title, null, xaxisLabel, series,
                            PlotOrientation.VERTICAL, false, false, false);
                    XYPlot plot = chart.getXYPlot();
                    plot.setRangeGridlinesVisible(false);
                    plot.setDomainGridlinesVisible(false);

                    XYItemRenderer renderer = plot.getRenderer();
                    renderer.setBasePaint(Color.white);
                    renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
                    float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
                    renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
                    plot.setRenderer(renderer);
                }

                chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));

                charts.get(efId).add(chart);
            }
        }
    }

    /*
     * DATES
     */
    charts.put(-1L, new ArrayList<JFreeChart>());
    for (Integer component : dateCorrelations.keySet()) {
        String xaxisLabel = componentShorthand + (component + 1);

        List<Date> dates = svdo.getDates();
        if (dates.isEmpty())
            break;

        long secspan = ubic.basecode.util.DateUtil.numberOfSecondsBetweenDates(dates);

        if (component >= MAX_COMP)
            break;
        Double a = dateCorrelations.get(component);

        if (a != null && !Double.isNaN(a)) {
            Double[] eigenGene = svdo.getvMatrix().getColObj(component);

            /*
             * Plot eigengene vs values, add correlation to the plot
             */
            TimeSeries series = new TimeSeries("Dates vs. eigen" + (component + 1));
            int i = 0;
            for (Date d : dates) {
                // if span is less than an hour, retain the minute.
                if (secspan < 60 * 60) {
                    series.addOrUpdate(new Minute(d), eigenGene[i++]);
                } else {
                    series.addOrUpdate(new Hour(d), eigenGene[i++]);
                }

            }
            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.addSeries(series);

            JFreeChart chart = ChartFactory.createTimeSeriesChart(
                    "Dates: " + xaxisLabel + " " + String.format("r=%.2f", a), null, xaxisLabel, dataset, false,
                    false, false);

            XYPlot xyPlot = chart.getXYPlot();

            chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));

            // standard renderer makes lines.
            XYDotRenderer renderer = new XYDotRenderer();
            renderer.setBaseFillPaint(Color.white);
            renderer.setDotHeight(3);
            renderer.setDotWidth(3);
            renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); // has no effect, need dotheight.
            float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
            renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            domainAxis.setVerticalTickLabels(true);
            xyPlot.setRenderer(renderer);
            xyPlot.setRangeGridlinesVisible(false);
            xyPlot.setDomainGridlinesVisible(false);
            charts.get(-1L).add(chart);

        }
    }

    /*
     * Plot in a grid, with each factor as a column. FIXME What if we have too many factors to fit on the screen?
     */
    int columns = (int) Math.ceil(charts.size());
    int perChartSize = ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX;
    BufferedImage image = new BufferedImage(columns * perChartSize, MAX_COMP * perChartSize,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    int currentX = 0;
    int currentY = 0;
    for (Long id : charts.keySet()) {
        for (JFreeChart chart : charts.get(id)) {
            this.addChartToGraphics(chart, g2, currentX, currentY, perChartSize, perChartSize);
            if (currentY + perChartSize < MAX_COMP * perChartSize) {
                currentY += perChartSize;
            } else {
                currentY = 0;
                currentX += perChartSize;
            }
        }
    }

    os.write(ChartUtilities.encodeAsPNG(image));
    return true;
}

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   www .  j  ava 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:msi.gama.outputs.layers.ChartLayerStatement.java

void createSeries(final IScope scope, final boolean isTimeSeries) throws GamaRuntimeException {
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setTickLabelFont(getTickFont());
    domainAxis.setLabelFont(getLabelFont());
    if (isTimeSeries) {
        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        if (timeSeriesXData == null) {
            timeSeriesXData = (ChartDataStatement) DescriptionFactory.create(IKeyword.DATA, description,
                    IKeyword.LEGEND, xAxisName, IKeyword.VALUE, SimulationAgent.CYCLE).compile();
            if (getFacet(IKeyword.TIMEXSERIES) != null) {
                timeSeriesXData.getDescription().getFacets().get(IKeyword.VALUE)
                        .setExpression(getFacet(IKeyword.TIMEXSERIES));
            }/*w  w w.ja v a2 s.  c  om*/
        }

        // FIXME: datas can NOT contain timeSeriesXData (a ChartDataStatement and not a ChartData)
        if (!datas.contains(timeSeriesXData)) {
            datas.add(0, timeSeriesXData.createData(scope));
        }
    }
    IExpression expr = getFacet(XRANGE);
    IExpression expr2 = getFacet(XTICKUNIT);
    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) {
                domainAxis.setFixedAutoRange(r);
                domainAxis.setAutoRangeMinimumSize(r);
            }
            domainAxis.setAutoRangeIncludesZero(false);
        } else if (range instanceof GamaPoint) {
            domainAxis.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) {
                domainAxis.setTickUnit(new NumberTickUnit(r));
            }
        }
    }
    if (datas.size() > 0) {
        domainAxis.setLabel(datas.get(0).getName());
    }
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setTickLabelFont(getTickFont());
    yAxis.setLabelFont(getLabelFont());
    expr = getFacet(YRANGE);
    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));
            }
        }
    }
    if (datas.size() == 2) {
        yAxis.setLabel(datas.get(1).getName());
        chart.removeLegend();
    }
    final LegendTitle ll = chart.getLegend();
    if (ll != null) {
        ll.setItemFont(getLegendFont());
    }

    for (int i = 0; i < datas.size(); i++) {
        ChartData e = datas.get(i);

        final String legend = e.getName();
        if (i != 0 | !isTimeSeries) { // the first data is the domain

            XYDataset data = plot.getDataset(i);
            XYSeries serie = new XYSeries(0, false, false);
            if (type == SERIES_CHART || type == XY_CHART) {
                dataset = new DefaultTableXYDataset();
                // final XYSeries nserie = new XYSeries(serie.getKey(), false, false);
                final XYSeries nserie = new XYSeries(e.getName(), false, false);
                ((DefaultTableXYDataset) dataset).addSeries(nserie);
            }
            if (type == SCATTER_CHART) {
                dataset = new XYSeriesCollection();
                final XYSeries nserie = new XYSeries(e.getName(), false, true);
                // final XYSeries nserie = new XYSeries(serie.getKey(), false, true);
                ((XYSeriesCollection) dataset).addSeries(nserie);
            }

            // dataset = new DefaultTableXYDataset();

            // final XYSeries serie = new XYSeries(legend, false, false);
            // final XYSeries serie = new XYSeries(legend, false, true);
            // ((DefaultTableXYDataset) dataset).addSeries(serie);
            expressions_index.put(legend, i);
            plot.setRenderer(i, (XYItemRenderer) e.getRenderer(), false);
            // final Color c = e.getColor();
            // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesPaint(0, c);
            // TODO Control this with a facet
            // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setBaseShapesFilled(false);
            // TODO Control this with a facet
            // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesShapesVisible(0, false);
            // if (type==SERIES_CHART)
            // plot.setDataset(i-1, (DefaultTableXYDataset) dataset);
            // else
            plot.setDataset(i, (XYDataset) dataset);
        }
        history.append(legend);
        history.append(',');

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

}

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

@Override
public void resetAxes(final IScope scope) {
    NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis();
    NumberAxis range2Axis = rangeAxis;/* w ww  . java 2s .co  m*/
    boolean secondaxis = false;
    if (getUseSecondYAxis(scope)) {
        secondaxis = true;
        range2Axis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(1);
        if (range2Axis == null) {
            NumberAxis secondAxis = new NumberAxis("");
            ((XYPlot) this.chart.getPlot()).setRangeAxis(1, secondAxis);
            range2Axis = secondAxis;
            range2Axis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(1);
            range2Axis = formatYAxis(scope, range2Axis);

            ((XYPlot) this.chart.getPlot()).setRangeAxis(1, range2Axis);
        }
    }

    if (getX_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(domainAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((XYPlot) this.chart.getPlot()).setDomainAxis(logAxis);
        domainAxis = logAxis;
    }
    if (getY_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        logAxis = (LogarithmicAxis) formatYAxis(scope, logAxis);
        ((XYPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;
    }
    if (secondaxis) {
        if (getY2_LogScale(scope)) {
            LogarithmicAxis logAxis = new LogarithmicAxis(range2Axis.getLabel());
            logAxis.setAllowNegativesFlag(true);
            logAxis = (LogarithmicAxis) formatYAxis(scope, logAxis);
            ((XYPlot) this.chart.getPlot()).setRangeAxis(1, logAxis);
            range2Axis = logAxis;
        }

    }

    if (!getUseXRangeInterval(scope) && !getUseXRangeMinMax(scope)) {
        domainAxis.setAutoRange(true);
    }

    if (this.getUseXRangeInterval(scope)) {
        domainAxis.setFixedAutoRange(getXRangeInterval(scope));
        domainAxis.setAutoRangeMinimumSize(getXRangeInterval(scope));
        domainAxis.setAutoRange(true);

    }
    if (this.getUseXRangeMinMax(scope)) {
        domainAxis.setRange(getXRangeMin(scope), getXRangeMax(scope));

    }
    if (this.getXTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setDomainGridlinePaint(this.tickColor);
        if (getXTickUnit(scope) > 0) {
            domainAxis.setTickUnit(new NumberTickUnit(getXTickUnit(scope)));
            ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(true);
        } else
            ((XYPlot) this.chart.getPlot())
                    .setDomainGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());

    } else {
        ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(false);

    }

    if (!getUseYRangeInterval(scope) && !getUseYRangeMinMax(scope)) {
        rangeAxis.setAutoRange(true);
    }

    if (this.getUseYRangeInterval(scope)) {
        rangeAxis.setFixedAutoRange(getYRangeInterval(scope));
        rangeAxis.setAutoRangeMinimumSize(getYRangeInterval(scope));
        rangeAxis.setAutoRange(true);
    }
    if (this.getUseYRangeMinMax(scope)) {
        rangeAxis.setRange(getYRangeMin(scope), getYRangeMax(scope));

    }
    if (this.getYTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setRangeGridlinePaint(this.tickColor);
        if (getYTickUnit(scope) > 0) {
            rangeAxis.setTickUnit(new NumberTickUnit(getYTickUnit(scope)));
            ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(true);
        } else
            ((XYPlot) this.chart.getPlot())
                    .setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());

    } else {
        ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false);

    }

    if (secondaxis) {
        if (!getUseY2RangeInterval(scope) && !getUseY2RangeMinMax(scope)) {
            range2Axis.setAutoRange(true);
        }

        if (this.getUseY2RangeInterval(scope)) {
            range2Axis.setFixedAutoRange(getY2RangeInterval(scope));
            range2Axis.setAutoRangeMinimumSize(getY2RangeInterval(scope));
            range2Axis.setAutoRange(true);
        }
        if (this.getUseY2RangeMinMax(scope)) {
            range2Axis.setRange(getY2RangeMin(scope), getY2RangeMax(scope));

        }
        if (this.getYTickLineVisible(scope)) {
            ((XYPlot) this.chart.getPlot()).setRangeGridlinePaint(this.tickColor);
            if (getY2TickUnit(scope) > 0) {
                range2Axis.setTickUnit(new NumberTickUnit(getY2TickUnit(scope)));
                ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(true);
            } else
                ((XYPlot) this.chart.getPlot())
                        .setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());

        } else {
            ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false);

        }

    }

    if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) {
        domainAxis.setLabel(getXLabel(scope));
    }
    if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) {
        rangeAxis.setLabel(getYLabel(scope));
    }
    if (secondaxis) {
        if (getY2Label(scope) != null && !getY2Label(scope).isEmpty()) {
            range2Axis.setLabel(getY2Label(scope));
        }

    }
    if (this.series_label_position.equals("none")) {
        (this.chart).getLegend().setVisible(false);
    }
    if (!this.getXTickValueVisible(scope)) {
        domainAxis.setTickMarksVisible(false);
        domainAxis.setTickLabelsVisible(false);

    }

}