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

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

Introduction

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

Prototype

public NumberAxis(String label) 

Source Link

Document

Constructs a number axis, using default values where necessary.

Usage

From source file:org.csml.tommo.sugar.heatmap.MappingQualityMatrixChart.java

private static PaintScaleLegend createPaintScaleLegend(PaintScale paintScale) {
    NumberAxis scaleAxis = new NumberAxis("");

    PaintScaleLegend scaleLegend = new PaintScaleLegend(paintScale, scaleAxis);
    scaleLegend.setAxisOffset(2.0);/*from   www  .ja va2s .  co  m*/
    scaleLegend.setPosition(RectangleEdge.RIGHT);
    scaleLegend.setMargin(new RectangleInsets(5, 1, 5, 1));
    return scaleLegend;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AreaChartExpression.java

/**
 * Creates a stacked area chart with default settings.  The chart object returned by this method uses a {@link
 * CategoryPlot} instance as the plot, with a {@link org.jfree.chart.axis.CategoryAxis} for the domain axis, a {@link
 * org.jfree.chart.axis.NumberAxis} as the range axis, and a {@link org.jfree.chart.renderer.category
 * .StackedAreaRenderer}/*from   w w w  .ja  v  a2 s.  c o m*/
 * as the renderer.
 *
 * @param title             the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel the label for the category axis (<code>null</code> permitted).
 * @param valueAxisLabel    the label for the value axis (<code>null</code> permitted).
 * @param dataset           the dataset for the chart (<code>null</code> permitted).
 * @param orientation       the plot orientation (horizontal or vertical) (<code>null</code> not permitted).
 * @param legend            a flag specifying whether or not a legend is required.
 * @param tooltips          configure chart to generate tool tips?
 * @param urls              configure chart to generate URLs?
 * @return A stacked area chart.
 */
private JFreeChart createStackedAreaChart(final String title, final String categoryAxisLabel,
        final String valueAxisLabel, final CategoryDataset dataset, final PlotOrientation orientation,
        final boolean legend, final boolean tooltips, final boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    final CategoryAxis categoryAxis = new FormattedCategoryAxis(categoryAxisLabel,
            getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale());
    categoryAxis.setCategoryMargin(0.0);
    final ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    final StackedAreaRenderer renderer = new StackedAreaRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:de.cebitec.readXplorer.plotting.CreatePlots.java

private synchronized static JFreeChart createCombinedChart(XYSeriesCollection normal, XYSeriesCollection posInf,
        XYSeriesCollection negInf, String xName, String yName, XYToolTipGenerator toolTip) {

    final NumberAxis domainAxis = new NumberAxis(xName);

    // create subplot 1...
    final XYDataset data1 = normal;
    final XYItemRenderer renderer1 = new XYShapeRenderer();
    renderer1.setBaseToolTipGenerator(toolTip);
    final NumberAxis rangeAxis1 = new NumberAxis(yName);
    final XYPlot subplot1 = new XYPlot(data1, domainAxis, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // create subplot 2...
    final XYDataset data2 = negInf;
    final XYItemRenderer renderer2 = new XYShapeRenderer();
    renderer2.setBaseToolTipGenerator(toolTip);
    final NumberAxis rangeAxis2 = new NumberAxis() {
        @Override//from  ww w .  j  a v  a2  s  .co m
        public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
            List myTicks = new ArrayList();
            myTicks.add(new NumberTick(0, "-Inf", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
            return myTicks;
        }
    };
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, domainAxis, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // create subplot 3...
    final XYDataset data3 = posInf;
    final XYItemRenderer renderer3 = new XYShapeRenderer();
    renderer3.setBaseToolTipGenerator(toolTip);
    final NumberAxis rangeAxis3 = new NumberAxis() {
        @Override
        public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
            List myTicks = new ArrayList();
            myTicks.add(new NumberTick(0, "Inf", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
            return myTicks;
        }
    };
    rangeAxis3.setAutoRangeIncludesZero(false);
    final XYPlot subplot3 = new XYPlot(data3, domainAxis, rangeAxis3, renderer3);
    subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis);
    plot.setGap(0);

    // add the subplots...
    plot.add(subplot3, 1);
    plot.add(subplot1, 10);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart(plot);

}

From source file:de.berlios.statcvs.xml.report.CommitActivityChart.java

public XYPlot createPlot(XYDataset dataset, String title) {
    NumberAxis valueAxis = new NumberAxis(title);
    valueAxis.setTickUnit(new NumberTickUnit(6.0, new DecimalFormat("0")));
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setLowerBound(0);/*from   w  ww  .  j  ava  2  s.  c  om*/
    valueAxis.setUpperBound(24);
    valueAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));

    return new XYPlot(dataset, null, valueAxis, new PointXYRenderer());
}

From source file:ecg.ecgshow.ECGShowUI.java

private void createECGData(long timeZone) {
    ECGData = new JPanel(new GridLayout(LEAD_COUNT, 1));
    dateAxises = new DateAxis[LEAD_COUNT];
    ECGSeries = new TimeSeries[LEAD_COUNT * 2];
    for (int i = 0; i < LEAD_COUNT; i++) {
        TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); //XYDataset  TimeSeriesCollection
        ECGSeries[i] = new TimeSeries("?" + (i + 1));
        ECGSeries[i].setMaximumItemCount(500);
        ECGSeries[i + LEAD_COUNT] = new TimeSeries("");
        ECGSeries[i + LEAD_COUNT].setMaximumItemAge(timeZone);
        ECGSeries[i + LEAD_COUNT].setMaximumItemCount(2);

        timeseriescollection.addSeries(ECGSeries[i]);
        timeseriescollection.addSeries(ECGSeries[i + LEAD_COUNT]);

        //DateAxis dateaxis = new DateAxis("Time");
        dateAxises[i] = new DateAxis("");
        dateAxises[i].setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016)));
        dateAxises[i].setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018)));
        dateAxises[i].setTickLabelsVisible(true);
        dateAxises[i].setVisible(false);

        //NumberAxis numberaxis = new NumberAxis("ecg");
        NumberAxis numberaxis = new NumberAxis("ecg");
        numberaxis.setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016)));
        numberaxis.setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018)));
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        numberaxis.setVisible(false);/*from w w  w.  jav  a2s  .c o  m*/
        numberaxis.setLowerBound(1500D);
        numberaxis.setUpperBound(3000D);

        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
        xylineandshaperenderer.setSeriesPaint(0, Color.GREEN); //
        xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2));
        xylineandshaperenderer.setSeriesPaint(1, Color.LIGHT_GRAY); //
        xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(5));

        XYPlot xyplot = new XYPlot(timeseriescollection, dateAxises[i], numberaxis, xylineandshaperenderer);
        xyplot.setBackgroundPaint(Color.LIGHT_GRAY);
        xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
        xyplot.setBackgroundPaint(Color.BLACK);

        JFreeChart jfreechart = new JFreeChart(xyplot);
        jfreechart.setBackgroundPaint(new Color(237, 237, 237));//?
        jfreechart.getLegend().setVisible(false);

        ChartPanel chartpanel = new ChartPanel(jfreechart, (int) (WIDTH * 46 / 100), (int) (HEIGHT * 17 / 100),
                0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, true, false, false);

        chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0) //??0
                , BorderFactory.createEmptyBorder() //????
        ));
        chartpanel.setMouseZoomable(false); //?
        ECGData.add(chartpanel);
    }
}

From source file:org.schreibubi.JCombinations.logic.visitors.ChartNodesVisitorOverlay.java

private void accumulateVisit(OurTreeNode o) throws Exception {
    this.dutYData = new ArrayList<ArrayList<Double>>();
    this.dutName = new ArrayList<String>();

    for (int i = 0; i < o.getChildCount(); i++)
        ((OurTreeNode) o.getChildAt(i)).accept(this);

    /*//from   w ww  . j a  va  2 s. c  o  m
     * ArrayList< Double > x = s.getXdataDefault().getXPositions(); for ( int j = 0; j < this.dutYData.size(); j++ ) {
     * ArrayList< Double > y = this.dutYData.get( j ); XYSeries xy = new XYSeries( this.dutName.get( j ) ); for ( int i =
     * 0; i < y.size(); i++ ) { xy.add( x.get( i ), y.get( i ) ); } this.xyseries.addSeries( xy ); }
     */
    NumberAxis xAxis = new NumberAxis(" X ");
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(" Y ");
    yAxis.setAutoRangeIncludesZero(false);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRendererExtended(true, true);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xyseries = new XYSeriesCollection();

    XYPlot plot = new XYPlot(xyseries, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    ExtendedJFreeChart chart = new ExtendedJFreeChart("Overlay", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    this.charts.add(chart);

}

From source file:org.drools.planner.benchmark.core.statistic.memoryuse.MemoryUseProblemStatistic.java

protected void writeGraphStatistic() {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries usedSeries = new XYSeries(singleBenchmark.getSolverBenchmark().getName() + " used");
        XYSeries maxSeries = new XYSeries(singleBenchmark.getSolverBenchmark().getName() + " max");
        for (MemoryUseSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement();
            usedSeries.add(timeMillisSpend, memoryUseMeasurement.getUsedMemory());
            maxSeries.add(timeMillisSpend, memoryUseMeasurement.getMaxMemory());
        }//from w  w w. j ava 2  s  . co m
        seriesCollection.addSeries(usedSeries);
        seriesCollection.addSeries(maxSeries);
    }
    NumberAxis xAxis = new NumberAxis("Time spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Memory");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYAreaRenderer2();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " memory use statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "MemoryUseStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<Float>> singleSerieDataPoints, ArrayList<String> singleSerieCategories,
        String singleSerieTitle) {

    super(applicationTitle);

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;
    this.Title = applicationTitle;

    this.dataPoints = new ArrayList<>();
    this.dataPoints.add(singleSerieDataPoints);
    this.categories = new ArrayList<>();
    this.categories.add(singleSerieCategories);
    this.seriesTitles = new ArrayList<>();
    this.seriesTitles.add(singleSerieTitle);

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);

    this.renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot, true);
    chart.setBackgroundPaint(Color.white);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setBackground(Color.white);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);//from  www .ja va  2  s  . com
    this.setDefaultCloseOperation(HIDE_ON_CLOSE);

}

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java

public JFreeChart createChart() {

    logger.debug("IN");
    CategoryPlot plot = new CategoryPlot();
    IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder();
    String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName");
    NumberAxis rangeAxis = new NumberAxis(rangeAxisName);
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    Color colorLabel = Color.decode("#000000");
    rangeAxis.setLabelPaint(colorLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    rangeAxis.setTickLabelPaint(colorLabel);
    plot.setRangeAxis(rangeAxis);//from  www. java2  s  .  c o  m

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setLabelPaint(colorLabel);
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setTickLabelPaint(colorLabel);
    plot.setDomainAxis(domainAxis);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    //I create a line renderer 
    MyStandardCategoryItemLabelGenerator generator = null;

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
    lineRenderer.setShapesFilled(true);
    lineRenderer.setBaseItemLabelGenerator(generator);
    lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12));
    lineRenderer.setBaseItemLabelPaint(colorLabel);
    lineRenderer.setBaseItemLabelsVisible(true);

    DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line");

    for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
        String serName = (String) iterator.next();
        String labelName = "";
        int index = -1;
        index = datasetLine.getRowIndex(serName);

        Color color = Color.decode("#990200");
        lineRenderer.setSeriesPaint(index, color);
    }

    plot.setDataset(0, datasetLine);
    plot.setRenderer(0, lineRenderer);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    logger.debug("Chart created");
    TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.setTitle(title);
    TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle);
    TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle2);
    chart.removeLegend();

    chart.setBackgroundPaint(Color.white);
    logger.debug("OUT");
    return chart;
}

From source file:edu.umn.natsrl.evaluation.ContourPlotter.java

private boolean createContourPlot() {

    if (chart != null) {
        return true;
    }//from   ww w.  j ava  2 s.  c o m

    if (this.cv == null || this.ncv == 0 || this.colors == null) {
        return false;
    }

    String date = null;
    Vector<EvaluationResult> results = (Vector<EvaluationResult>) this.eval.getResult().clone();

    if (results.size() > 2) {
        date = "  [average of " + (results.size() - 1) + " days]";
    } else {
        date = "  [" + results.get(0).getName() + "]";
    }

    final String title = section.getName() + date;
    final String xAxisLabel = "";
    final String yAxisLabel = "";
    final String zAxisLabel = "";

    this.xAxis = new NumberAxis(xAxisLabel);
    this.yAxis = new NumberAxis(yAxisLabel);
    this.zColorBar = new ColorBar(zAxisLabel);

    if (this.xAxis instanceof NumberAxis) {
        ((NumberAxis) this.xAxis).setAutoRangeIncludesZero(false);
    }

    this.yAxis.setAutoRangeIncludesZero(false);

    this.yAxis.setStreetName(this.streetNames);
    ((NumberAxis) this.xAxis).setTime(this.plotTimes);
    ((NumberAxis) this.zColorBar.getAxis()).setColor(cv, unit);
    ((NumberAxis) this.xAxis).setLowerMargin(0.0);
    ((NumberAxis) this.xAxis).setUpperMargin(0.0);

    this.yAxis.setLowerMargin(0.0);
    this.yAxis.setUpperMargin(0.0);
    this.xAxis.setRange(0, numX - 1);
    this.yAxis.setRange(0, numY - 1);
    this.zColorBar.getAxis().setTickMarksVisible(true);

    final ContourDataset data = createDataset();
    //        for(Number n : data.getZValues()) {
    //            System.out.println("Data=" + n);
    //        }
    final ContourPlot plot = new ContourPlot(data, this.xAxis, this.yAxis, this.zColorBar, ncv);

    plot.SetContourValue(cv, ncv, colors, numX, numY);
    plot.setDataAreaRatio(ratio);

    chart = new JFreeChart(title, null, plot, false);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));

    return true;
}