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:net.commerce.zocalo.freechart.ChartGenerator.java

private static ValueAxis setLowerBoundsZero(JFreeChart chart) {
    ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
    rangeAxis.setLowerMargin(40);/*from w ww  .  ja  v a 2 s  .  co  m*/
    rangeAxis.setLowerBound(0.0);
    return rangeAxis;
}

From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java

/**
 * This function creates the measurement graph by using the JFreeChart
 * library. The X axis of the graph is in minutes.
 * //  w w  w  . j  av a  2  s  . c  om
 * @param plotList
 *            plotlist to save. Xvalues must be stored in milliseconds.
 * @param associatedName
 *            Name of the list
 * @param folderWhereResultsAreSaved
 *            folder where results are saved
 * @param yLabel
 *            Name of the y label
 * @param pictureFile
 *            name of the file
 * @param yDivisor
 *            use to divide measurements stored in the plotlist by yDivisor
 */
public static void generateGraphWithJFreeChart(PlotList plotList, String associatedName,
        String folderWhereResultsAreSaved, String yLabel, String pictureFile, float yDivisor) {

    // Create a new XYSeries
    // XYSeries are used to represent couples of (x,y) values.
    XYSeries data = new XYSeries(associatedName);

    int size = plotList.getSize();
    if (size == 0) {
        // no element in graphics, exit
        //Logger.getLogger(this.getClass() ).warn("Nothing in graph");
        return;
    }

    // Find the initial value of the time
    // Due to the fact that getX(i) <= getX(i+1),
    // min({0<=i<size / getX(i)}) = getX(0)
    long initialValue = plotList.getX(0);

    XYSeriesCollection series = new XYSeriesCollection(data);
    if (!plotList.getunit().equals(""))
        yLabel += " (" + plotList.getunit() + ")";
    // Create a new XY graph.
    //JFreeChart chart = ChartFactory.createXYLineChart("", "Time", yLabel, series, PlotOrientation.VERTICAL, true, true, false);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time (min:sec)", yLabel, series, true, true,
            false);
    // Set the graph format
    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 10));
    RelativeDateFormat rdf = new RelativeDateFormat(initialValue);
    rdf.setSecondFormatter(new DecimalFormat("00"));
    axis.setDateFormatOverride(rdf);

    // Fill the JFreeChart object which will be used to create the Graph
    for (int i = 0; i < size; i++) {
        // xvalue must be in
        double xval = ((Long) plotList.getX(i)).doubleValue();
        float yval = plotList.getY(i).floatValue() / yDivisor;
        // Logger.getLogger(this.getClass() ).debug(associatedName + " [" + (((Long)
        // plotList.getX(i)).floatValue() - initialValue)
        // / XDIVISOR +"] "+ yval);
        data.add(xval, yval);
    }

    ValueAxis rangeAxis = plot.getRangeAxis();
    Long min = plotList.getMin();
    Long max = plotList.getMax();
    double diff = (max - min) * 0.02;
    if (diff == 0)
        diff = max * 0.0001;

    rangeAxis.setLowerBound((min - diff) / yDivisor);
    rangeAxis.setUpperBound((max + diff) / yDivisor);
    //      Logger.getLogger(this.getClass() ).debug("(" + (min / yDivisor) * 0.98 + " - "
    //            + (min / yDivisor) * 0.98 + ")");
    //      Logger.getLogger(this.getClass() ).debug("Bound = " + rangeAxis.getLowerBound() + " - "
    //            + rangeAxis.getUpperBound());
    //      Logger.getLogger(this.getClass() ).debug("Margin = " + rangeAxis.getLowerMargin() + " - "
    //            + rangeAxis.getUpperMargin());
    //      Logger.getLogger(this.getClass() ).debug("NB AXIS = " + plot.getRangeAxisCount());

    // save the chart in a picture file.
    BufferedImage bufImage = chart.createBufferedImage(640, 480);
    File fichier = new File(pictureFile);
    try {
        if (!ImageIO.write(bufImage, "png", fichier)) {
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:msec.org.Tools.java

public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
    if (data[0].getValues().length != 1440) {
        return "data size invalid";
    }//from   ww w  . j av  a 2s  .  co m
    if (data.length > 1) {
        if (data[1].getValues() == null || data[1].getValues().length != 1440) {
            return "data 1 invalid";
        }
    }

    XYDataset xydataset = createDataset(data);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        GregorianCalendar endgc = (GregorianCalendar) gc.clone();
        endgc.add(GregorianCalendar.DATE, 1);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:msec.org.Tools.java

public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart,
        String title, int duration) {
    if (data.size() == 0) {
        return "data size invalid";
    }//from ww  w  .  ja  v  a  2s  .  c o m

    int date = Integer.parseInt(data.get(0).getDate());
    GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100);

    XYDataset xydataset = createDaysDataset(data, startgc, chart);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        dateaxis.setMinimumDate(startgc.getTime());
        GregorianCalendar endgc = (GregorianCalendar) startgc.clone();
        endgc.add(GregorianCalendar.DATE, duration);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:ch.zhaw.ias.dito.ui.util.BlockPlotPanel.java

public BlockPlotPanel(Matrix m, double lowerBound, double upperBound) {
    super(new BorderLayout());
    NumberAxis xAxis = new NumberAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(1.0);/*  w ww .jav a  2  s.co m*/
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(1.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            XYZDataset xyzDataset = (XYZDataset) dataset;
            double x = xyzDataset.getXValue(series, item);
            double y = xyzDataset.getYValue(series, item);
            double z = xyzDataset.getZValue(series, item);
            return ("X=" + x + ", Y=" + y + ", Z=" + z);
        }
    });
    PaintScale scale = new ColorPaintScale(lowerBound, upperBound);
    renderer.setPaintScale(scale);
    ValueAxis axis = new NumberAxis();
    axis.setLowerBound(scale.getLowerBound());
    axis.setUpperBound(scale.getUpperBound());
    PaintScaleLegend legend = new PaintScaleLegend(scale, axis);
    legend.setMargin(new RectangleInsets(10, 10, 10, 10));
    legend.setPosition(RectangleEdge.RIGHT);

    MatrixXYDataset dataset = new MatrixXYDataset(m);
    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    chart = new JFreeChart(plot);
    chart.removeLegend();
    chart.addSubtitle(legend);
    chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDisplayToolTips(true);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurvePanel.java

public void updateDatasetFor(String name, double min, double max, XYDataset dataset) {
    JFreeChart c = charts.get(name);//  w  w  w.  j av a 2  s  .c om
    XYPlot plot = (XYPlot) c.getPlot();
    plot.setDataset(dataset);
    setXYPlotRenderer(plot);

    ValueAxis axis = plot.getRangeAxis();
    axis.setLowerBound(min);
    axis.setUpperBound(max);

}

From source file:org.apache.qpid.disttest.charting.chartbuilder.BaseChartBuilder.java

private void configureYAxisBounds(final ChartingDefinition chartingDefinition, final JFreeChart chart) {
    if (chart.getPlot() != null && chart.getPlot() instanceof XYPlot) {
        ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
        if (chartingDefinition.getYAxisLowerBound() != null) {
            rangeAxis.setLowerBound(chartingDefinition.getYAxisLowerBound());
        }/*  ww w . jav  a 2  s .  c  o  m*/
        if (chartingDefinition.getYAxisUpperBound() != null) {
            rangeAxis.setUpperBound(chartingDefinition.getYAxisUpperBound());
        }
    }
}

From source file:com.marvelution.jira.plugins.hudson.charts.BuildTestResultsRatioChartGenerator.java

/**
 * {@inheritDoc}/*from w w  w  .  j  a  va  2  s . com*/
 */
@Override
public ChartHelper generateChart() {
    buildMap = new HashMap<Integer, Build>();
    final CategoryTableXYDataset dataset = new CategoryTableXYDataset();
    for (Build build : builds) {
        final TestResult results = build.getTestResult();
        double percentagePass = 0.0D, percentageFail = 0.0D, percentageSkipped = 0.0D;
        if (results != null && results.getTotal() > 0) {
            percentagePass = Double.valueOf(results.getPassed()) / Double.valueOf(results.getTotal()) * 100.0D;
            percentageFail = Double.valueOf(results.getFailed()) / Double.valueOf(results.getTotal()) * 100.0D;
            percentageSkipped = Double.valueOf(results.getSkipped()) / Double.valueOf(results.getTotal())
                    * 100.0D;
        }
        dataset.add(Double.valueOf(build.getBuildNumber()), percentagePass, seriesNames[0]);
        dataset.add(Double.valueOf(build.getBuildNumber()), percentageFail, seriesNames[1]);
        dataset.add(Double.valueOf(build.getBuildNumber()), percentageSkipped, seriesNames[2]);
        buildMap.put(Integer.valueOf(build.getBuildNumber()), build);
    }
    final JFreeChart chart = ChartFactory.createStackedXYAreaChart("", "",
            getI18n().getText("hudson.charts.tests"), dataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);
    XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setDataset(1, dataset);
    if (dataset.getItemCount() > 0) {
        XYLineAndShapeRenderer shapeRenderer = new XYLineAndShapeRenderer(false, true);
        shapeRenderer.setSeriesShapesVisible(1, false);
        shapeRenderer.setSeriesLinesVisible(1, false);
        shapeRenderer.setSeriesShapesVisible(2, false);
        shapeRenderer.setSeriesLinesVisible(2, false);
        shapeRenderer.setSeriesShape(0, new Ellipse2D.Double(-3.0D, -3.0D, 6.0D, 6.0D));
        shapeRenderer.setSeriesPaint(0, GREEN_PAINT);
        shapeRenderer.setSeriesShapesFilled(0, true);
        shapeRenderer.setBaseToolTipGenerator(this);
        shapeRenderer.setBaseItemLabelFont(ChartDefaults.defaultFont);
        shapeRenderer.setBaseItemLabelsVisible(false);
        xyPlot.setRenderer(0, shapeRenderer);
        StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
        renderer.setSeriesPaint(0, GREEN_PAINT);
        renderer.setSeriesPaint(1, RED_PAINT);
        renderer.setSeriesPaint(2, YELLOW_PAINT);
        renderer.setBaseItemLabelFont(ChartDefaults.defaultFont);
        renderer.setBaseItemLabelsVisible(false);
        xyPlot.setRenderer(1, renderer);
        renderer.setBaseToolTipGenerator(this);
    }
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    rangeAxis.setLowerBound(0.0D);
    rangeAxis.setUpperBound(100.0D);
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setLowerBound(Collections.min(buildMap.keySet()));
    domainAxis.setUpperBound(Collections.max(buildMap.keySet()));
    final TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    domainAxis.setStandardTickUnits(ticks);
    xyPlot.setDomainAxis(domainAxis);
    ChartUtil.setupPlot(xyPlot);
    return new ChartHelper(chart);
}

From source file:playground.dgrether.signalsystems.utils.DgSignalPlanChart.java

public JFreeChart createSignalPlanChart(String title, String xAxisTitle, String yAxisTitle) {
    JFreeChart chart = ChartFactory.createStackedBarChart(title, xAxisTitle, yAxisTitle, this.dataset,
            PlotOrientation.HORIZONTAL, false, false, false);
    DgDefaultAxisBuilder axis = new DgDefaultAxisBuilder();
    CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    CategoryAxis xAxis = axis.createCategoryAxis(xAxisTitle);
    plot.setDomainAxis(xAxis);//from w  ww .j  a v a2s .  c  o m
    ValueAxis yAxis = axis.createValueAxis(yAxisTitle);
    yAxis.setUpperBound(this.tMax);
    yAxis.setLowerBound(this.tMin);
    plot.setRangeAxis(yAxis);

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.findRangeBounds(dataset);
    renderer.setShadowVisible(false);
    //      renderer.setItemMargin(10.005);
    renderer.setMaximumBarWidth(0.2);
    for (Entry<Integer, Color> ee : seriesColor.entrySet()) {
        renderer.setSeriesPaint(ee.getKey(), ee.getValue());
        //         renderer.setSeriesStroke(ee.getKey(), new BasicStroke(50));
    }
    plot.setRenderer(renderer);
    //      chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    //      chart.setBackgroundPaint(ChartColor.WHITE);
    //      chart.removeLegend();
    return chart;
}

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

private void makeChart() {
    dataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("", "Time Interval", "Throughput (Gbps)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(bg);//from  w  w w.  j a  va  2 s.  c  om
    TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15));
    ttitle.setPaint(Color.WHITE);
    chart.setTitle(ttitle);

    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    ValueAxis axis = plot.getRangeAxis();
    axis.setUpperBound(64.0);
    axis.setLowerBound(0.0);
    axis.setTickLabelPaint(new Color(185, 185, 185));
    axis.setLabelPaint(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(0x2e, 0x90, 0x18));//(0x17, 0x7b, 0x7c));
    renderer.setSeriesPaint(1, new Color(0x12, 0x45, 0x73));//(0xa2, 0x45, 0x73)
    renderer.setSeriesPaint(3, new Color(0xff, 0x80, 0x40));
    renderer.setSeriesPaint(2, new Color(0x6f, 0x2c, 0x85));
    renderer.setSeriesPaint(4, new Color(0xa1, 0x60, 0x98));
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000")));
    //renderer.setMaximumBarWidth(0.05);
    //        addDummy();
}