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

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

Introduction

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

Prototype

public void setTickUnit(NumberTickUnit unit) 

Source Link

Document

Sets the tick unit for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

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. j a  v a 2  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:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java

/**
 * Prepare the plot//from ww w  .  ja  va 2 s .  co  m
 * 
 * @param chart
 *            jfreechart chart
 * @param displayed
 *            displayed time interval
 */
private void preparePlot(boolean first, JFreeChart chart, TimeInterval displayed) {
    // Plot customization
    plot = chart.getXYPlot();
    // Grid and background colors
    plot.setBackgroundPaint(BACKGROUND_PAINT);
    plot.setDomainGridlinePaint(DOMAIN_GRIDLINE_PAINT);
    plot.setRangeGridlinePaint(RANGE_GRIDLINE_PAINT);
    // Tooltip
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(TOOLTIP_GENERATOR);
    // Disable bar white stripes
    XYBarRenderer barRenderer = (XYBarRenderer) plot.getRenderer();
    barRenderer.setBarPainter(new StandardXYBarPainter());
    // X axis
    X_FORMAT.setTimeUnit(TimeUnit.getTimeUnit(currentShownTrace.getTimeUnit()));
    X_FORMAT.setContext(displayed.startTimestamp, displayed.endTimestamp, true);
    NumberAxis xaxis = (NumberAxis) plot.getDomainAxis();
    xaxis.setTickLabelFont(TICK_LABEL_FONT);
    xaxis.setLabelFont(LABEL_FONT);
    xaxis.setNumberFormatOverride(X_FORMAT);
    TickDescriptor des = X_FORMAT.getTickDescriptor(displayed.startTimestamp, displayed.endTimestamp,
            numberOfTicks);
    xaxis.setTickUnit(new NumberTickUnit(des.delta));
    xaxis.addChangeListener(new AxisChangeListener() {
        @Override
        public void axisChanged(AxisChangeEvent arg) {
            long max = ((Double) plot.getDomainAxis().getRange().getUpperBound()).longValue();
            long min = ((Double) plot.getDomainAxis().getRange().getLowerBound()).longValue();
            TickDescriptor des = X_FORMAT.getTickDescriptor(min, max, numberOfTicks);
            NumberTickUnit newUnit = new NumberTickUnit(des.delta);
            NumberTickUnit currentUnit = ((NumberAxis) arg.getAxis()).getTickUnit();
            // ensure we don't loop
            if (!currentUnit.equals(newUnit)) {
                ((NumberAxis) arg.getAxis()).setTickUnit(newUnit);
            }
        }
    });
    // Y axis
    NumberAxis yaxis = (NumberAxis) plot.getRangeAxis();
    yaxis.setTickLabelFont(TICK_LABEL_FONT);
    yaxis.setLabelFont(LABEL_FONT);
    // remove the marker, if any
    if (marker != null) {
        plot.removeDomainMarker(marker);
        marker = null;
    }
}

From source file:no.met.jtimeseries.chart.ChartPlotter.java

public void addThresholdLineChart(TimeBase timeBase, NumberPhenomenon ph, PlotStyle plotStyle) {
    NumberPhenomenon phenomenon = ph.clone();
    if (phenomenon.getItems().size() > 0) {
        XYItemRenderer renderer = RendererFactory.createRenderer(SplineStyle.STANDARD);
        // if using hybrid
        if (plotStyle.getSplineStyle().equalsIgnoreCase(SplineStyle.HYBRID)) {
            phenomenon.doHybridSpline(0.5d, 4);
            renderer = RendererFactory.createRenderer(SplineStyle.NONE);
        }/*from  w  w w  . j av a 2s . c  o  m*/

        if (plotStyle.getNonNegative()) {
            phenomenon.removeNegativeValues();
        }

        // add threshold point into the dataset
        phenomenon.addThresholdPoints(plotStyle.getThreshold());
        // create threshold data set with specified threshold value
        XYDataset dataset = phenomenon.getTimeSeriesWithThreshold(plotStyle.getTitle(), timeBase,
                plotStyle.getThreshold());

        // render even series lines with color1 and odd series lines with
        // color2
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            if (i % 2 == 0)
                renderer.setSeriesPaint(i, plotStyle.getPlusDegreeColor());
            else
                renderer.setSeriesPaint(i, plotStyle.getMinusDegreeColor());
            renderer.setSeriesStroke(i, plotStyle.getStroke());
            // hidden legend
            renderer.setSeriesVisibleInLegend(i, false);
        }

        plot.setDataset(plotIndex, dataset);
        plot.setRenderer(plotIndex, renderer);

        NumberAxis numberAxis;
        // null check for number axis
        if (plotStyle.getNumberAxis() == null) {
            numberAxis = new NumberAxis(plotStyle.getTitle());
            numberAxis.setAutoRangeIncludesZero(false);
            numberAxis.setLabelPaint(plotStyle.getLabelColor());
            numberAxis.setTickLabelPaint(plotStyle.getLabelColor());

            // ugly calculation
            double max = phenomenon.getMaxValue();
            double min = phenomenon.getMinValue();
            int tUnit = getTemperatureTicksUnit(max, min);
            int[] range = calculateAxisMaxMin(phenomenon, tUnit, plotStyle.getTotalTicks());

            NumberTickUnit ntu = new NumberTickUnit(tUnit);
            numberAxis.setTickUnit(ntu);
            numberAxis.setLowerMargin(LOWER_PLOT_MARGIN);
            numberAxis.setRangeWithMargins(range[1], range[0]);
        } else {
            numberAxis = plotStyle.getNumberAxis();
        }

        plot.setRangeAxis(rangeAxisIndex, numberAxis);

        Date minDate = phenomenon.getStartTime();
        Date maxDate = phenomenon.getEndTime();

        DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
        domainAxis.setRange(minDate, maxDate);

        plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex);

        plotIndex++;
        rangeAxisIndex++;
    }
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());

    plot.setNoDataMessage(chartDefinition.getNoDataMessage());

    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(),
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }/*  w  w  w. j a  v a2  s .com*/
    plot.setOutlineStroke(null); // TODO define outline stroke

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }

            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }

    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            } else {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                        "{0} = {1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }

        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));

    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        }
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private void setNumberAxisStyles(NumberAxis axis, UIAxis comp) {
    axis.setInverted(comp.isInverted());

    Object lowerBound = comp.getLowerBound();
    Object upperBound = comp.getUpperBound();
    Double lowerMargin = comp.getLowerMargin();
    Double upperMargin = comp.getUpperMargin();

    if (lowerBound != null)
        axis.setLowerBound(Coercion.coerceToDouble(lowerBound));
    if (upperBound != null)
        axis.setUpperBound(Coercion.coerceToDouble(upperBound));
    if (lowerMargin != null)
        axis.setLowerMargin(lowerMargin);
    if (upperMargin != null)
        axis.setUpperMargin(upperMargin);

    Double tickStep = comp.getTickStep();
    String tickFormat = comp.getTickLabelFormat();

    if ((tickStep != null && tickStep > 0) || tickFormat != null) {
        if (tickFormat == null) {
            axis.setTickUnit(new NumberTickUnit(tickStep));
        } else if (tickStep == null) {
            NumberFormat format = new DecimalFormat(tickFormat);
            axis.setNumberFormatOverride(format);
        } else {//from w w  w  .  java 2 s .co m
            NumberFormat format = new DecimalFormat(tickFormat);
            axis.setTickUnit(new NumberTickUnit(tickStep, format));
        }
    }
}

From source file:no.met.jtimeseries.chart.ChartPlotter.java

/**
 * Add a line chart in the plot//from   w w  w.j a  v  a2  s.co  m
 * 
 * @param timeBase
 *            The base time of the data: second, minute, hour, year or auto
 * @param phenomenon
 *            Phenomenon to plot.
 * @param plotStyle
 *            The style preference for the plot
 * 
 */
public void addLineChart(TimeBase timeBase, NumberPhenomenon ph, PlotStyle plotStyle) {
    NumberPhenomenon phenomenon = ph.clone();
    if (phenomenon.getItems().size() > 0) {
        XYItemRenderer renderer = RendererFactory.createRenderer(SplineStyle.STANDARD);
        // if using hybrid spline
        if (plotStyle.getSplineStyle().equalsIgnoreCase(SplineStyle.HYBRID)) {
            phenomenon.doHybridSpline(0.5d, 4);
            renderer = RendererFactory.createRenderer(SplineStyle.NONE);
        }

        if (plotStyle.getNonNegative()) {
            phenomenon.removeNegativeValues();
        }

        XYDataset dataset = phenomenon.getTimeSeries(plotStyle.getTitle(), timeBase);

        renderer.setSeriesPaint(0, plotStyle.getSeriesColor());
        renderer.setSeriesStroke(0, plotStyle.getStroke());

        // hidden the legend by default
        renderer.setSeriesVisibleInLegend(0, false);

        plot.setDataset(plotIndex, dataset);
        plot.setRenderer(plotIndex, renderer);

        // render the range axis
        NumberAxis numberAxis;
        // null check for number axis
        if (plotStyle.getNumberAxis() == null) {
            numberAxis = new NumberAxis(plotStyle.getTitle());
            numberAxis.setAutoRangeIncludesZero(false);
            numberAxis.setLabelPaint(plotStyle.getLabelColor());
            numberAxis.setTickLabelPaint(plotStyle.getLabelColor());

            // ugly calculation
            double max = phenomenon.getMaxValue();
            double min = phenomenon.getMinValue();
            // increase and decrease max, min respectiivly to get the
            // difference pf atleast 50
            while ((max - min) <= plotStyle.getDifference()) {
                max++;
                min--;
            }
            int tUnit = (int) ((max - min) / plotStyle.getTotalTicks());
            if (tUnit <= 1) {
                tUnit = 2;
            }
            int[] range = calculateAxisMaxMin(phenomenon, tUnit, plotStyle.getTotalTicks());

            NumberTickUnit ntu = new NumberTickUnit(tUnit);
            numberAxis.setTickUnit(ntu);
            numberAxis.setRangeWithMargins(range[1], range[0]);
        } else {
            numberAxis = plotStyle.getNumberAxis();
        }
        plot.setRangeAxis(rangeAxisIndex, numberAxis);

        Date minDate = phenomenon.getStartTime();
        Date maxDate = phenomenon.getEndTime();

        DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
        domainAxis.setRange(minDate, maxDate);

        plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex);

        plotIndex++;
        rangeAxisIndex++;
    }
}

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

private void createChart() {

    String title = "Correlation Scatter Plot  correlationCoefficient=" + nf.format(corrValue) + " N="
            + dataPoints.size();/*w  w  w  .ja v  a  2 s .c  om*/

    corrChart = ChartFactory.createScatterPlot(title, xLabel, yLabel, null, PlotOrientation.VERTICAL, true,
            true, false);

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

    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.
    List<PlotPoint> plotPoints = new ArrayList<PlotPoint>(dataPoints);
    DataRange Xrange = PlotPoint.getDataRange(plotPoints, AxisType.X_AXIS);
    DataRange Yrange = PlotPoint.getDataRange(plotPoints, AxisType.Y_AXIS);

    //        Double xAbsMax = Math.max(Math.abs(Xrange.getMaxRange()), Math.abs(Xrange.getMinRange()));
    //        Double yAbsMax = Math.max(Math.abs(Yrange.getMaxRange()), Math.abs(Yrange.getMinRange()));
    //        
    //        Double maxAbsVal = Math.max(xAbsMax, yAbsMax);

    domainAxis.setAutoRangeIncludesZero(false);

    double xTick = 10.0;
    double yTick = 10.0;

    double xdist = Math.abs(Xrange.getMaxRange() - Xrange.getMinRange());
    double ydist = Math.abs(Yrange.getMaxRange() - Yrange.getMinRange());
    if (xdist < 10.0) {
        xTick = 1.0;
    }

    if (ydist < 10.0) {
        yTick = 1.0;
    }

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

    domainAxis.setTickUnit(new NumberTickUnit(xTick));
    rangeAxis.setTickUnit(new NumberTickUnit(yTick));

    //double glyphScaleFactor = (maxAbsVal*2.0)/600.0;   //assuming 600 pixels for the graph
    double xScale = xdist / 600.0;
    //double glyphScaleFactor = 1.0;
    double yScale = ydist / 600.0;

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

    //domainAxis.setRange(-maxAbsVal, maxAbsVal);
    double xMin = Xrange.getMinRange() - xScale * glyphSize;
    double xMax = Xrange.getMaxRange() + xScale * glyphSize;
    double yMin = Yrange.getMinRange() - yScale * glyphSize;
    double yMax = Yrange.getMaxRange() + yScale * glyphSize;

    domainAxis.setRange(xMin, xMax);

    //rangeAxis.setRange(-maxAbsVal, maxAbsVal);
    rangeAxis.setRange(yMin, yMax);
    Set<SampleInfo> infoSet = new HashSet<SampleInfo>();

    if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) {
        String geneName = null;
        if ((colorBy == ColorByType.IHC_EXPRESSION_X) && (ct1 != ContinuousType.GENE)) {
            logger.info("User attempted to color by ihc x on non gene continuous type.");
            //need to show validation error
            return;
        } else if ((colorBy == ColorByType.IHC_EXPRESSION_Y) && (ct2 != ContinuousType.GENE)) {
            logger.info("User attempted to color by ihc y on non gene continuous type.");
            //need to show validation error
            return;
        } else {
            if (colorBy == ColorByType.IHC_EXPRESSION_X) {
                //parse the gene name from the xLabel
                geneName = xLabel.substring(0, xLabel.indexOf('_'));
            } else if (colorBy == ColorByType.IHC_EXPRESSION_Y) {
                //parse the gene name from the yLabel
                geneName = yLabel.substring(0, yLabel.indexOf('_'));
            }
        }

        //Get the IHC data for the samples to be graphed   
        LevelOfExpressionIHCService loeService = LevelOfExpressionIHCService.getInstance();
        LossOfExpressionIHCService lossService = LossOfExpressionIHCService.getInstance();
        Set<String> sampleIds = new HashSet<String>();
        String labtrackId;
        SampleInfo info;
        for (ISPYPlotPoint corrPoint : dataPoints) {
            info = corrPoint.getSampleInfo();
            if (info != null) {
                labtrackId = corrPoint.getSampleInfo().getLabtrackId();
                sampleIds.add(labtrackId);
                infoSet.add(info);
            } else {
                logger.warn("Point id=" + corrPoint.getId() + " has no sample info. Skipping point");
            }
        }

        Collection<? extends Finding> loeFindings = loeService.getFindingsFromSampleInfo(infoSet);
        Collection<? extends Finding> lossFindings = lossService.getFindingsFromSampleInfo(infoSet);

        List<IHCFinding> findings = new ArrayList<IHCFinding>();

        for (Finding f : loeFindings) {
            findings.add((IHCFinding) f);
        }

        for (Finding f : lossFindings) {
            findings.add((IHCFinding) f);
        }

        //        Need to handle mapping names to IHC biomarker names.
        //EGFR (ok), FAK (PTK2), HER2 (ERBB2), Ki-67, P53, bcl2 (ok), p27, CYCLIN_D1 (CCND1)
        //Translate the gene names into the biomarker names 
        //used by ihc. This code should be removed once protein biomarker
        //alias is implmented.
        String ihcBiomarker = geneName;
        if (geneName.equalsIgnoreCase("PTK2")) {
            ihcBiomarker = "FAK";
            ihcBiomarkerType = IHCBiomarkerType.FAK;
        } else if (geneName.equalsIgnoreCase("ERBB2")) {
            ihcBiomarker = "HER2";
            ihcBiomarkerType = IHCBiomarkerType.HER2;
        } else if (geneName.equalsIgnoreCase("MKI67")) {
            //need to check this one
            ihcBiomarker = "Ki-67";
            ihcBiomarkerType = IHCBiomarkerType.KI67;
        } else if (geneName.equalsIgnoreCase("TP53")) {
            ihcBiomarker = "P53";
            ihcBiomarkerType = IHCBiomarkerType.P53;
        } else if (geneName.equalsIgnoreCase("Cdkn1b")) {
            ihcBiomarker = "P27";
            ihcBiomarkerType = IHCBiomarkerType.P27;
        } else if (geneName.equalsIgnoreCase("BCL2")) {
            ihcBiomarker = "BCL2";
            ihcBiomarkerType = IHCBiomarkerType.BCL2;
        } else if (geneName.equalsIgnoreCase("EGFR")) {
            ihcBiomarker = "EGFR";
            ihcBiomarkerType = IHCBiomarkerType.EGFR;
        } else if (geneName.equalsIgnoreCase("CCND1")) {
            ihcBiomarker = "CYCLIN_D1";
            ihcBiomarkerType = IHCBiomarkerType.CYCLIN_D1;
        }

        List<IHCFinding> filteredList = getIHCFindingsForBiomarker(findings, ihcBiomarker);

        //TEST Case
        //          Set<String> testIds = new HashSet<String>();
        //          testIds.add("212833");
        //          testIds.add("213152");

        //Collection<? extends Finding> loeFindings = loeService.getFindingsFromSampleIds(testIds);

        //Collection<? extends Finding> lossFindings = lossService.getFindingsFromSampleIds(sampleIds);

        ihcData = new HashMap<String, List<IHCFinding>>();
        IHCFinding loeFinding;
        List<IHCFinding> findingList;
        Specimen specimen = null;
        String patientDID = null;
        for (Finding finding : filteredList) {
            loeFinding = (IHCFinding) finding;
            specimen = loeFinding.getSpecimen();
            if ((specimen != null) && (specimen.getPatientDID() != null)) {
                patientDID = specimen.getPatientDID();
                findingList = ihcData.get(patientDID);

                if (findingList == null) {
                    findingList = new ArrayList<IHCFinding>();
                    ihcData.put(patientDID, findingList);
                }

                findingList.add(loeFinding);
            } else {
                logger.warn(
                        "loeFinding id=" + loeFinding.getId() + " has null specimen or patientDID. Skipping..");
            }

        }
        //          IHCFinding lossFinding;
        //          for (Finding finding : lossFindings) {
        //           lossFinding = (IHCFinding) finding;
        //            ihcData.put(lossFinding.getId(), lossFinding);
        //          }

    }

    createGlyphsAndAddToPlot(plot, xScale, yScale);

    // 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);

    corrChart.setBackgroundPaint(p);

    buildLegend();

}

From source file:com.chart.SwingChart.java

/**
 * Set lower and upper limits for an ordinate
 * @param axis Axis to configure/*from   www . j  a v a2s  .  c om*/
 */
void setOrdinateRange(final NumberAxis axis) {
    axis.setAutoRange(false);
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));
    final TextField tfMax;
    final TextField tfMin;
    final TextField tfTick;
    final TextField tfFuente;
    grid.add(new Label("Axis"), 0, 0);
    grid.add(new Label(axis.getLabel()), 1, 0);
    grid.add(new Label("Lower"), 0, 1);
    grid.add(tfMin = new TextField(), 1, 1);
    grid.add(new Label("Upper"), 0, 2);
    grid.add(tfMax = new TextField(), 1, 2);
    grid.add(new Label("Space"), 0, 3);
    grid.add(tfTick = new TextField(), 1, 3);

    tfMin.setText(String.valueOf(axis.getLowerBound()));
    tfMax.setText(String.valueOf(axis.getUpperBound()));
    tfTick.setText(String.valueOf(axis.getTickUnit().getSize()));

    new PseudoModalDialog(skeleton, grid, true) {
        @Override
        public boolean validation() {
            axis.setLowerBound(Double.valueOf(tfMin.getText()));
            axis.setUpperBound(Double.valueOf(tfMax.getText()));
            axis.setTickUnit(new NumberTickUnit(Double.valueOf(tfTick.getText())));
            return true;
        }
    }.show();

}

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);//  w w w . jav  a2s. com

    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:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

private void customizeAxis(ChartDefinition cd, ChartAxis ai, NumberAxis axis) {
    customizeAxisEx(cd, ai, axis);//from   ww  w. j a  va  2 s .  c  om

    ChartInfo ci = (ChartInfo) cd.getChartHandlerInfo();
    double[] bounds = null;

    if (cd.getSeriesCount() > 0) {
        if (ai.isRangeAxis()) {
            bounds = ci.yAxisValues;
        } else {
            bounds = ci.xAxisValues;
        }
    }

    if (bounds != null) {
        axis.setLowerBound(bounds[0]);
        axis.setUpperBound(bounds[1]);
        axis.setTickUnit(new NumberTickUnit(bounds[2]));
    } else {
        RenderableDataItem u = ai.getUpperBounds();
        RenderableDataItem l = ai.getLowerBounds();
        double inc = ai.getIncrement();

        if (u != null) {
            axis.setUpperBound(u.doubleValue());
        }

        if (l != null) {
            axis.setLowerBound(l.doubleValue());
        }

        if (inc > 0) {
            axis.setTickUnit(new NumberTickUnit(inc));
        }
    }

    axis.setVisible(ai.isVisible());
}