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:ChartUsingJava.CombinedXYPlotDemo1.java

/**
 * Creates an overlaid chart./*from w w w  .j a v  a2s . c  o m*/
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {

    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {
        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            } else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}

From source file:org.spantus.exp.segment.draw.DrawDtw.java

protected JFreeChart createXYZChart() {
    NumberAxis xAxis = new NumberAxis("Sample");
    NumberAxis yAxis = new NumberAxis("target");
    List<List<Double>> data = info.getDistanceMatrix();
    XYZDataset xyzset = new XYZArrayDataset(data);
    XYPlot plot = new XYPlot(xyzset, xAxis, yAxis, null);
    XYBlockRenderer r = new XYBlockRenderer();
    PaintScale ps = new GrayPaintScale(min, max);
    //      LookupPaintScale ps = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    //      ps.add(1, Color.red);
    //      ps.add(2, Color.green);
    //      ps.add(3, Color.gray);

    r.setPaintScale(ps);/*www .ja  va 2s .com*/
    r.setBlockHeight(1.0f);
    r.setBlockWidth(1.0f);
    plot.setRenderer(r);
    JFreeChart chart = new JFreeChart("Chart Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    NumberAxis scaleAxis = new NumberAxis("Scale");
    scaleAxis.setUpperBound(100);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 12));
    //      PaintScaleLegend legend = new PaintScaleLegend(ps, scaleAxis);
    //      legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    //      legend.setPadding(new RectangleInsets(5, 5, 5, 5));
    //      legend.setStripWidth(50);
    //      legend.setPosition(RectangleEdge.RIGHT);
    //      legend.setBackgroundPaint(Color.WHITE);
    //      chart.addSubtitle(legend);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java

/**
 * Creates a new demo./*  w ww  . j a v a2  s .  com*/
 *
 * @param title the frame title.
 * @param pf
 */
public BestAgentsRoundInfoCollected(final String title, ArrayList<Double> pf) {

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    /*for (String mode : aMode) {
    info.put(mode, new ArrayList());
    }*/

    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);
    System.out.println("info" + info);
    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round of Best Agents " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("BestAgentsRound" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:tl.lib.dataCollection.gui.TimeSeriesChart.java

public TimeSeriesChart(_CollectionGUIScenario scenario, String label, String description, String labelAxisY) {
    super(null);/* w  w  w .  ja va 2 s.  com*/
    this.sourceDescriptor = scenario.getSourceDescriptor();
    this.collection = new XYSeriesCollection();

    // ChartTheme currentTheme = new StandardChartTheme("JFree");
    ValueAxis timeAxis = new DateAxis("Time");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(labelAxisY);
    valueAxis.setAutoRangeIncludesZero(false); // override default

    XYToolTipGenerator toolTipGenerator = null;
    toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    // XYURLGenerator urlGenerator = new StandardXYURLGenerator();
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    // renderer.setURLGenerator(urlGenerator);

    this.plot = new XYPlot(collection, timeAxis, valueAxis, renderer);

    this.chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    // currentTheme.apply(chart);

    renderingInfo = new ChartRenderingInfo();

    this.scenario = scenario;
    this.description = description;
    this.label = label;
    this.selected = new Vector<SourceId>();
    default_all = true;
    super.setChart(chart);
}

From source file:playground.anhorni.surprice.analysis.SupriceBoxPlot.java

public JFreeChart createChart() {
    String title = chartTitle;/*from www .j av  a2  s .co  m*/

    final CategoryAxis xAxis = new CategoryAxis(this.xAxisName);
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis(this.yAxisName);
    yAxis.setAutoRangeIncludesZero(true);

    if (Math.abs(yrangeLower - yrangeUpper) > Double.MIN_VALUE) {
        yAxis.setRange(yrangeLower, yrangeUpper);
    }

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:org.jfree.chart.demo.StatisticalBarChartDemo.java

/**
 * Creates a new demo.//from w  w w  .  ja v a  2  s .c o m
 *
 * @param title  the frame title.
 */
public StatisticalBarChartDemo(final String title) {

    super(title);
    final StatisticalCategoryDataset dataset = createDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    xAxis.setLowerMargin(0.01d); // percentage of space before first bar
    xAxis.setUpperMargin(0.01d); // percentage of space after last bar
    xAxis.setCategoryMargin(0.05d); // percentage of space between categories
    final ValueAxis yAxis = new NumberAxis("Value");

    // define the plot
    final CategoryItemRenderer renderer = new StatisticalBarRenderer();
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo", new Font("Helvetica", Font.BOLD, 14),
            plot, true);
    //chart.setBackgroundPaint(Color.white);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:playground.artemc.calibration.charts.AddSecondChart.java

public void addChartAndAxis() {

    //this.plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));       
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    //final CategoryAxis domainAxis = plot.getDomainAxis();
    //domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

    final ValueAxis axis2 = new NumberAxis(yAxisLabel);
    axis2.setRange(lowerLimit, upperLimit);
    plot.setRangeAxis(1, axis2);/* w  ww.j  a va 2 s  . c om*/
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    plot.setRenderer(1, renderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainGridlinesVisible(true);

}

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Generates a plot for comparing to datasets
 * @param title the name of the plot/*from w w w  .  j a v a  2s.  c  om*/
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 * @return a chart object for displaying or saving as picture
 */
public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            "Input Value", // y-axis label
            dataset1, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    XYPlot plot = chart.getXYPlot();

    Axis axis1 = plot.getRangeAxis(0);
    axis1.setLabelPaint(Color.red);

    NumberAxis axis2 = new NumberAxis("Twitter");
    axis2.setLabelPaint(Color.blue);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(1, renderer);

    return chart;
}

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

/**
 * Creates a new demo./*from w ww.  ja v  a  2 s  .com*/
 *
 * @param applicationTitle
 * @param chartTitle
 * @param xTitle
 * @param yTitle
 * @param dataPoints
 * @param categories
 * @param seriesTitles
 */
public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<ArrayList<Float>>> dataPoints, ArrayList<ArrayList<String>> categories,
        ArrayList<String> seriesTitles) {

    super(applicationTitle);

    this.dataPoints = dataPoints;
    this.categories = categories;
    this.seriesTitles = seriesTitles;

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

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

    final CategoryAxis xAxis = new CategoryAxis(this.xAxisTitle);
    final NumberAxis yAxis = new NumberAxis(this.yAxisTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(this.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(800, 500));
    setContentPane(this.chartPanel);

    this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createEvolution() {
    JFreeChart chart = ChartFactory.createXYLineChart("Evolution of Mean Agent Vision and Metabolism", "Time",
            "Level", model.evolution_vision_coll, PlotOrientation.VERTICAL, true, true, false);
    model.evolution_chart = chart;/*from  ww  w .j a va 2s. c om*/
    NumberAxis rangeAxis1 = new NumberAxis("Time");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins");
    XYPlot plot = chart.getXYPlot();
    ValueAxis xAxis = plot.getDomainAxis();

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    plot.setDataset(1, model.evolution_metabolism_coll);
    renderer.setSeriesPaint(1, Color.BLUE);
    return chart;
}