Example usage for org.jfree.data Range Range

List of usage examples for org.jfree.data Range Range

Introduction

In this page you can find the example usage for org.jfree.data Range Range.

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.Meter.java

/**
 * Creates the chart ./*  w w w . j a  va2  s  .  co  m*/
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart .
 */

public JFreeChart createChart(DatasetMap datasets) {

    Dataset dataset = (Dataset) datasets.getDatasets().get("1");

    MeterPlot plot = new MeterPlot((ValueDataset) dataset);
    plot.setRange(new Range(lower, upper));

    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval interval = (KpiInterval) iterator.next();

        plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()),
                Color.lightGray, new BasicStroke(2.0f), interval.getColor()));
    }

    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.CHORD);
    plot.setMeterAngle(260);
    plot.setTickLabelsVisible(true);
    //set tick label style
    Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
    plot.setTickLabelFont(tickLabelsFont);
    plot.setTickLabelPaint(labelsTickStyle.getColor());
    plot.setTickSize(5.0);
    plot.setTickPaint(Color.lightGray);
    if (units != null) {
        plot.setUnits(units);
    }

    plot.setValuePaint(labelsValueStyle.getColor());
    plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    return chart;
}

From source file:de.saring.util.gui.jfreechart.StackedRenderer.java

/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset./*from  w w w . j a  v a 2  s.  c o  m*/
 *
 * @param dataset the dataset (<code>null</code> permitted).
 * @return The range (or <code>null</code> if the dataset is
 *         <code>null</code> or empty).
 */
@Override
public Range findRangeBounds(XYDataset dataset) {
    if (dataset == null) {
        return null;
    }
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    TableXYDataset d = (TableXYDataset) dataset;
    int itemCount = d.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        double[] stackValues = getStackValues((TableXYDataset) dataset, d.getSeriesCount(), i);
        min = Math.min(min, stackValues[0]);
        max = Math.max(max, stackValues[1]);
    }
    if (min == Double.POSITIVE_INFINITY) {
        return null;
    }
    return new Range(min, max);
}

From source file:fi.smaa.jsmaa.gui.views.CriterionView.java

private JPanel buildValueFunctionChartPanel(ScaleCriterion criterion) {
    UtilityFunctionDataset dataset = new UtilityFunctionDataset(criterion);

    JFreeChart chart = ChartFactory.createXYLineChart("", "x", "v(x)", dataset, PlotOrientation.VERTICAL, false,
            true, true);//from  w  w  w .jav  a  2  s. c om

    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(0, renderer);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3.0f));
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

    ValueAxis rAxis = plot.getRangeAxis();
    rAxis.setAutoRange(false);
    rAxis.setRange(new Range(-0.03, 1.03));
    ValueAxis dAxis = plot.getDomainAxis();
    dAxis.setLowerMargin(0.03);
    dAxis.setUpperMargin(0.03);

    ChartPanel chartPanel = new ChartPanel(chart, false, true, true, false, true);
    chartPanel.addChartMouseListener(new ValueFunctionMouseListener(chartPanel, criterion, parent));

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setToolTipText("Click to add/remove partial value function points");
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setMouseZoomable(false);

    plot.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairLockedOnData(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    FormLayout layout = new FormLayout("left:pref", "p, 3dlu, p");

    PanelBuilder builder = new PanelBuilder(layout);
    CellConstraints cc = new CellConstraints();
    builder.add(chartPanel, cc.xy(1, 1));
    builder.add(new ValueFunctionPointsPanel(criterion), cc.xy(1, 3));

    return builder.getPanel();
}

From source file:org.jfree.data.Range.java

/**
 * Creates a new range by combining two existing ranges.
 * <P>/*from   w  w w.j av  a 2  s  . c  om*/
 * Note that:
 * <ul>
 *   <li>either range can be <code>null</code>, in which case the other
 *       range is returned;</li>
 *   <li>if both ranges are <code>null</code> the return value is
 *       <code>null</code>.</li>
 * </ul>
 *
 * @param range1  the first range (<code>null</code> permitted).
 * @param range2  the second range (<code>null</code> permitted).
 *
 * @return A new range (possibly <code>null</code>).
 */
public static Range combine(Range range1, Range range2) {
    if (range1 == null) {
        return range2;
    }
    if (range2 == null) {
        return range1;
    }
    double l = Math.min(range1.getLowerBound(), range2.getLowerBound());
    double u = Math.max(range1.getUpperBound(), range2.getUpperBound());
    return new Range(l, u);
}

From source file:pharoslabut.logger.CompassLoggerGUI.java

/**
 * Creates a chart.// ww  w .j  av a  2  s . c  o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Proteus Robot Compass Measurements", // chart title
            "Time (s)", // x axis label
            "Angle (radians)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customization...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setRange(new Range(0, 140));

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    // change the auto tick unit selection to integer units only...
    //        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(new Range(-Math.PI, Math.PI));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.jfree.data.RangeTest.java

/**
 * A simple test for the scale() method.
 *///w  w  w .j  a  va 2  s.  c o  m
@Test
public void testShift() {
    Range r1 = new Range(10.0, 20.0);
    Range r2 = Range.shift(r1, 20.0);
    assertEquals(30.0, r2.getLowerBound(), 0.001);
    assertEquals(40.0, r2.getUpperBound(), 0.001);

    r1 = new Range(0.0, 100.0);
    r2 = Range.shift(r1, -50.0, true);
    assertEquals(-50.0, r2.getLowerBound(), 0.001);
    assertEquals(50.0, r2.getUpperBound(), 0.001);

    r1 = new Range(-10.0, 20.0);
    r2 = Range.shift(r1, 20.0, true);
    assertEquals(10.0, r2.getLowerBound(), 0.001);
    assertEquals(40.0, r2.getUpperBound(), 0.001);

    r1 = new Range(-10.0, 20.0);
    r2 = Range.shift(r1, -30.0, true);
    assertEquals(-40.0, r2.getLowerBound(), 0.001);
    assertEquals(-10.0, r2.getUpperBound(), 0.001);

    r1 = new Range(-10.0, 20.0);
    r2 = Range.shift(r1, 20.0, false);
    assertEquals(0.0, r2.getLowerBound(), 0.001);
    assertEquals(40.0, r2.getUpperBound(), 0.001);

    r1 = new Range(-10.0, 20.0);
    r2 = Range.shift(r1, -30.0, false);
    assertEquals(-40.0, r2.getLowerBound(), 0.001);
    assertEquals(0.0, r2.getUpperBound(), 0.001);

    // Shifting with a delta of 0 does not change the range
    r2 = Range.shift(r1, 0.0);
    assertEquals(r1, r2);

    try {
        Range.shift(null, 0.1);
        fail("Null value is accepted");
    } catch (Exception e) {
    }
}

From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java

/**
 * Create a snp interval histogram without any axes
 * @param intervals/*from   w ww.  ja va2  s.  c om*/
 *          the intervals to use
 * @param startInBasePairs
 *          where should we start the graph?
 * @param extentInBasePairs
 *          how far should the graph extend
 * @param visualInterval
 *          the visual interval to use
 * @return
 *          the histogram
 */
public JFreeChart createSnpIntervalHistogram(final List<? extends RealValuedBasePairInterval> intervals,
        final long startInBasePairs, final long extentInBasePairs,
        final HighlightedSnpInterval visualInterval) {
    // create the axes
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs));
    NumberAxis yAxis = new NumberAxis();

    // hide the axes
    xAxis.setVisible(false);
    yAxis.setVisible(false);

    // create the plot
    XYPlot plot = this.createSnpIntervalHistogramPlot(intervals, visualInterval, xAxis, yAxis);

    // more hiding
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));

    // create the final chart
    JFreeChart histogram = new JFreeChart(plot);
    histogram.removeLegend();

    return histogram;
}

From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java

/**
 * Some checks for the add() method.//from  w w w  .  j  a v  a  2  s  .  c o  m
 */
@Test
public void testAdd() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList());
    dataset.add(item1, "R1", "C1");

    assertEquals(2.0, dataset.getValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(1.0, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(2.0, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(3.0, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON);
    assertEquals(4.0, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON);
    assertEquals(5.0, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(6.0, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(7.0, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON);
    assertEquals(8.0, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON);
    assertEquals(new Range(7.0, 8.0), dataset.getRangeBounds(false));
}

From source file:ec.ui.chart.RevisionChartPanel.java

private void setRange(TimeSeriesCollection ref, TimeSeriesCollection series) {
    double min, max;
    Range c = ref.getRangeBounds(true);//from w  ww.  j a v a 2s . c om

    min = c.getLowerBound();
    max = c.getUpperBound();

    if (series != null && series.getSeriesCount() != 0) {
        Range s = series.getRangeBounds(true);
        if (min > s.getLowerBound()) {
            min = s.getLowerBound();
        }

        if (max < s.getUpperBound()) {
            max = s.getUpperBound();
        }
    }

    min -= (Math.abs(min) * .03);
    max += (Math.abs(max) * .03);

    panel.getChart().getXYPlot().getRangeAxis().setRange(new Range(min, max));
}

From source file:com.xilinx.ultrascale.gui.BarCharts.java

License:asdf

public void setaRange() {
    CategoryPlot plot = chart.getCategoryPlot();
    ValueAxis axis = plot.getRangeAxis();

    //        axis.setUpperBound(1000.0);
    //        axis.setLowerBound(0.0);
    //        axis.setAutoRangeMinimumSize(1.0);
    axis.setAutoRange(true);/*ww w  .jav  a2 s . c om*/
    //        axis.setLowerMargin(0);
    axis.setLowerMargin(0);
    axis.setUpperMargin(0.40);
    axis.setAutoRangeMinimumSize(1.0);
    axis.setDefaultAutoRange(new Range(0, 1000));
}