Example usage for org.jfree.chart.axis ValueAxis setLowerBound

List of usage examples for org.jfree.chart.axis ValueAxis setLowerBound

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis setLowerBound.

Prototype

public void setLowerBound(double min) 

Source Link

Document

Sets the lower bound for the axis range.

Usage

From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AggregationExecutionChartBuilder.java

@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    plot.setRenderer(renderer);//  www .j a  va 2 s .  c o m

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index++, Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new DefaultTooltipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable<?> valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0.01);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(1.0);

    if (rangeAxis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setTickUnit(new NumberTickUnit(.10));
        numberAxis.setNumberFormatOverride(PERCENT_FORMATTER);
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:org.utgenome.core.cui.DrawHistogram.java

public void execute() throws Exception {

    InputStream in = null;//from   www  .  j a v  a 2s .  c  o  m
    if ("-".equals(input)) {
        _logger.info("reading from STDIN");
        in = new StandardInputStream();
    } else {
        _logger.info("reading from " + input);
        in = new FileInputStream(input);
    }

    List<Double> data = new ArrayList<Double>();
    BufferedReader dataSetInput = new BufferedReader(new InputStreamReader(in));
    int lineCount = 1;
    try {
        // read data set
        boolean cutOffTail = !Double.isNaN(xMax);
        boolean cutOffHead = !Double.isNaN(xMin);
        for (String line; (line = dataSetInput.readLine()) != null; lineCount++) {

            if (lineCount % 100000 == 0)
                _logger.info(String.format("read %,d data points", lineCount));

            if (line.startsWith("#"))
                continue;
            double v = Double.parseDouble(line);
            if (cutOffTail && v > xMax)
                continue;
            if (cutOffHead && v < xMin)
                continue;

            data.add(v);
        }

        double[] value = new double[data.size()];
        for (int i = 0; i < data.size(); ++i) {
            value[i] = data.get(i);
        }

        // draw histogram
        HistogramDataset dataSet = new HistogramDataset();
        dataSet.setType(HistogramType.FREQUENCY);
        dataSet.addSeries("data", value, numBins);
        JFreeChart chart = ChartFactory.createHistogram(null, null, "Frequency", dataSet,
                PlotOrientation.VERTICAL, false, false, false);

        if (title != null) {
            chart.setTitle(title);
        }

        ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
        if (cutOffHead) {
            domainAxis.setLowerBound(xMin);
        }
        if (cutOffTail) {
            domainAxis.setUpperBound(xMax);
        }
        if (xLabel != null) {
            domainAxis.setLabel(xLabel);
        }

        if (yLog) {
            LogarithmicAxis logAxis = new LogarithmicAxis("Frequency");
            logAxis.setAllowNegativesFlag(true);
            logAxis.setAutoRangeIncludesZero(true);
            chart.getXYPlot().setRangeAxis(logAxis);
        }

        if (!Double.isNaN(yMin)) {
            chart.getXYPlot().getRangeAxis().setLowerBound(yMin);
        }
        if (!Double.isNaN(yMax)) {
            chart.getXYPlot().getRangeAxis().setUpperBound(yMax);
        }

        File outputFile = new File(output);
        _logger.info("output to " + outputFile);
        ChartUtilities.saveChartAsPNG(outputFile, chart, width, height);

    } catch (Exception e) {
        throw new Exception(String.format("error at line %d: %s", lineCount, e));
    }

}

From source file:virgil.meanback.HistoryInfo.java

public void printChart(Stock stock, List<String[]> list, int days) throws Exception {
    //?//from w  ww. j ava  2  s  . c  o  m
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //
    standardChartTheme.setRegularFont(new Font("", Font.BOLD, 12));
    //?
    standardChartTheme.setLargeFont(new Font("", Font.BOLD, 18));
    //?
    ChartFactory.setChartTheme(standardChartTheme);
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    for (int i = list.size() - 1; i >= 0; i--) {
        String[] s = (String[]) list.get(i);
        dataSet.addValue(Double.parseDouble(s[1]), days + "", s[0]);
        dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "", s[0]);
        float sub = Float.parseFloat(s[2]);
        float error = Float.parseFloat(s[3]);
        if (sub > error * 2) {
            dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "??", s[0]);
        }
    }

    //?????Legend
    //????
    //??URL
    JFreeChart chart = ChartFactory.createLineChart(
            stock.getName() + "(" + stock.getCode() + ") ", "", "", dataSet,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot cp = chart.getCategoryPlot();
    cp.setBackgroundPaint(ChartColor.WHITE); // 
    CategoryAxis categoryAxis = cp.getDomainAxis();
    //  Lable 90 
    Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 10);
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    categoryAxis.setTickLabelFont(labelFont);//X?? 
    ValueAxis yAxis = cp.getRangeAxis();
    yAxis.setAutoRange(true);
    double[] d = getAxiasThresold(stock, list);
    yAxis.setLowerBound(d[0] - 0.15);
    yAxis.setUpperBound(d[1] + 0.15);
    LineAndShapeRenderer lasp = (LineAndShapeRenderer) cp.getRenderer();
    lasp.setBaseFillPaint(ChartColor.RED);
    lasp.setDrawOutlines(true);
    lasp.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) cp.getRenderer(1);//?
    DecimalFormat decimalformat1 = new DecimalFormat("##.##");//???
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
    //????
    renderer.setItemLabelsVisible(true);//
    renderer.setBaseItemLabelsVisible(true);//
    //?????
    renderer.setShapesFilled(Boolean.TRUE);//??
    renderer.setShapesVisible(true);//?
    ChartFrame chartFrame = new ChartFrame("??", chart, true);
    //chart?JavaChartFramejavaJframe????
    chartFrame.pack(); //??
    chartFrame.setVisible(true);//???
}

From source file:org.mwc.cmap.xyplot.views.CrossSectionViewer.java

protected CrossSectionViewer(final Composite parent) {
    _chartFrame = new ChartComposite(parent, SWT.NONE, null, true) {
        @Override// ww w  .j a  v a  2  s  . co  m
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };

    _chart = ChartFactory.createXYLineChart("Cross Section", // Title
            "Distance (km)", // X-Axis label
            "Elevation (m)", // Y-Axis label
            _dataset, // Dataset,
            PlotOrientation.VERTICAL, true, // Show legend,
            true, // tooltips
            true // urs
    );

    // Fix the axises start at zero
    final ValueAxis yAxis = _chart.getXYPlot().getRangeAxis();
    yAxis.setLowerBound(0);
    final ValueAxis xAxis = _chart.getXYPlot().getDomainAxis();
    xAxis.setLowerBound(0);

    _chartFrame.setChart(_chart);
    _chartFrame.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            clearPlot();
            _chartFrame.removeDisposeListener(this);
        }
    });
}

From source file:com.xilinx.virtex7.PowerChart.java

private void makeChart() {
    dataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("", "Time Interval", "", dataset, PlotOrientation.HORIZONTAL, true,
            true, false);/*from   ww  w .  j av a 2  s.c  o m*/

    TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15));
    ttitle.setPaint(Color.WHITE);
    chart.setTitle(ttitle);
    chart.setBackgroundPaint(bg);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ValueAxis axis = plot.getRangeAxis();
    axis.setUpperBound(10.0);
    TickUnits tickUnits = new TickUnits();
    tickUnits.add(new NumberTickUnit(2));
    axis.setStandardTickUnits(tickUnits);
    axis.setLowerBound(0.0);
    axis.setTickLabelPaint(new Color(185, 185, 185));

    CategoryAxis caxis = plot.getDomainAxis();
    caxis.setTickLabelPaint(new Color(185, 185, 185));
    caxis.setLabelPaint(new Color(185, 185, 185));

    renderer.setItemMargin(0);
    renderer.setSeriesPaint(0, new Color(0x17, 0x7b, 0x7c));
    renderer.setSeriesPaint(1, new Color(0xa2, 0x45, 0x73));
    renderer.setSeriesPaint(2, new Color(0xff, 0x80, 0x40));
    renderer.setSeriesPaint(3, new Color(0x6f, 0x2c, 0x85));
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000")));
    addDummy();
}

From source file:org.mwc.cmap.xyplot.views.CrossSectionViewer.java

public void fillPlot(final Layers theLayers, final LineShape line, final ICrossSectionDatasetProvider prov,
        final long timePeriod) {
    if (theLayers != null && line != null) {
        _timePeriod = timePeriod;/*from   ww  w  .  j ava  2 s .c om*/
        _datasetProvider = prov;
        _dataset.removeAllSeries();

        if (_currentTime != null) {
            if (isSnail()) {
                final HiResDate startDTG = new HiResDate(_currentTime.getDate().getTime() - _timePeriod);
                _dataset = _datasetProvider.getDataset(line, theLayers, startDTG, _currentTime);
                final Map<Integer, Color> colors = _datasetProvider.getSeriesColors();
                for (Integer seriesKey : colors.keySet()) {
                    setSnailRenderer(seriesKey, colors.get(seriesKey));
                }
                _chart.getXYPlot().setRenderer(_snailRenderer);
            } else {
                _dataset = _datasetProvider.getDataset(line, theLayers, _currentTime);
                final Map<Integer, Color> colors = _datasetProvider.getSeriesColors();
                for (Integer seriesKey : colors.keySet()) {
                    setDiscreteRenderer(seriesKey, colors.get(seriesKey));
                }
                _chart.getXYPlot().setRenderer(_discreteRenderer);
            }

        }

        double maxY = 0;
        double minY = Integer.MAX_VALUE;

        for (int i = 0; i < _dataset.getSeriesCount(); i++) {
            final XYSeries series = _dataset.getSeries(_dataset.getSeriesKey(i));
            final double y = series.getMaxY();
            if (maxY < y)
                maxY = y;
            final double mY = series.getMinY();
            if (minY > mY)
                minY = mY;
        }
        final ValueAxis yAxis = _chart.getXYPlot().getRangeAxis();
        yAxis.setUpperBound(maxY + TICK_OFFSET);
        yAxis.setLowerBound(minY - TICK_OFFSET);

        final ValueAxis xAxis = _chart.getXYPlot().getDomainAxis();
        xAxis.setUpperBound(getXAxisLength(line) + TICK_OFFSET);
        xAxis.setLowerBound(0);

        _chart.getXYPlot().setDataset(_dataset);

    }
}

From source file:org.xwiki.rendering.internal.macro.chart.source.AxisConfigurator.java

/**
 * Set the limits of a number axis.// ww w.j  ava2 s . c  o m
 *
 * @param axis The axis.
 * @param index The index of the axis
 * @throws MacroExecutionException if the parameters could not be parsed as numbers.
 */
private void setNumberLimits(ValueAxis axis, int index) throws MacroExecutionException {
    try {
        if (axisLowerLimit[index] != null) {
            Number number = NumberUtils.createNumber(StringUtils.trim(axisLowerLimit[index]));
            axis.setLowerBound(number.doubleValue());
        }
        if (axisUpperLimit[index] != null) {
            Number number = NumberUtils.createNumber(StringUtils.trim(axisUpperLimit[index]));
            axis.setUpperBound(number.doubleValue());
        }
    } catch (NumberFormatException e) {
        throw new MacroExecutionException("Invalid number in axis bound.", e);
    }
}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

public void setChartPanelRanges(int axis, double low, double high) {
    XYPlot plot = (XYPlot) this.chartPanel.getChart().getPlot();
    ValueAxis newaxis = new NumberAxis();
    newaxis.setLowerBound(low);
    newaxis.setUpperBound(high);/*ww w  .ja v  a 2s.  c o m*/
    if (axis == XYChartPanel.XAXIS) {
        plot.setDomainAxis(newaxis);
    } else if (axis == XYChartPanel.YAXIS) {
        plot.setRangeAxis(newaxis);
    }
}

From source file:RDGraphGenerator.java

/**
 * Creates a sample chart./*from   w w  w . ja v  a  2s. com*/
 *
 * @param dataset  the dataset for the chart.
 *
 * @return A sample chart.
 */
private JFreeChart createDistChart(String riderID) {

    String riderName = (String) riders.get(riderID);
    final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Distances", // chart title
            "Month", // domain axis label
            mainDist, // range axis label
            (CategoryDataset) riderDistances.get(riderID), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("0", "G1");
    map.mapKeyToGroup("1", "G1");
    map.mapKeyToGroup("2", "G1");
    map.mapKeyToGroup("3", "G1");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    ValueAxis va = (ValueAxis) plot.getRangeAxis();
    ValueAxis ova = null;
    try {
        ova = (ValueAxis) va.clone();
    } catch (CloneNotSupportedException cnse) {
    }
    ova.setLabel(secondaryDist);
    ova.setLowerBound(va.getLowerBound() * unitConversion);
    ova.setUpperBound(va.getUpperBound() * unitConversion);
    plot.setRangeAxis(1, ova);
    plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
    CategoryAxis ca = plot.getDomainAxis();
    ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    //Make around the chart transparent.
    chart.setBackgroundPaint(null);
    return chart;

}

From source file:jenkins.plugins.livingdoc.chart.ProjectSummaryChart.java

private void adjustBound(ValueAxis valueAxis) {
    // Since we are showing the ItemLabel on top, add a gap to the
    // upper-bound value to make sure the
    // ItemLabel is fully visible(did try with ItemLabelPosition without
    // success!)/*from   w w w .  j a  v a 2s. c o  m*/
    // @todo : need to find a better solution
    int gap = (int) (20 * upperBoundCount / (double) DEFAULT_CHART_HEIGHT);

    valueAxis.setUpperBound(upperBoundCount + (gap < 7 ? 7 : gap));
    valueAxis.setLowerBound(lowerBoundCount);
}