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:test.FastScatterDemo.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title  the frame title.// ww w  . ja va  2 s.  c o m
 */
public FastScatterDemo(final String title) {

    super(title);
    populateData();
    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    //        chart.setLegend(null);

    // force aliasing of the rendered content..
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    //      panel.setHorizontalZoom(true);
    //    panel.setVerticalZoom(true);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);

}

From source file:org.esa.beam.smos.visat.GridPointBtDataFlagmatrixToolView.java

@Override
protected JComponent createGridPointComponent() {
    dataset = new DefaultXYZDataset();

    final NumberAxis xAxis = new NumberAxis("Record #");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);//w w  w  .ja  v  a2s. co m
    xAxis.setUpperMargin(0.0);

    flagNames = createFlagNames(Dddb.getInstance().getFlagDescriptors(DEFAULT_FLAG_DESCRIPTOR_IDENTIFIER));
    final NumberAxis yAxis = createRangeAxis(flagNames);

    final LookupPaintScale paintScale = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    paintScale.add(0.0, Color.BLACK);
    paintScale.add(1.0, Color.RED);
    paintScale.add(2.0, Color.GREEN);
    paintScale.add(3.0, Color.BLUE);
    paintScale.add(4.0, Color.YELLOW);

    final XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    renderer.setBaseToolTipGenerator(new FlagToolTipGenerator(flagNames));

    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setForegroundAlpha(0.5f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage("No data");

    chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java

public static void createBoxplot(DefaultBoxAndWhiskerCategoryDataset scatterDataset, PrintStream outStream,
        String title, String xAxisLabel, String yAxisLabel, Font lableFont) throws IOException {

    CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
    xAxis.setLabelFont(lableFont);/* w w  w .  j  a v a2  s  .co  m*/
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setTickLabelFont(lableFont);
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setRange(0, 100);
    yAxis.setLabelFont(lableFont);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    renderer.setBaseLegendTextFont(lableFont);
    renderer.setStroke(new BasicStroke(5.0f));

    CategoryPlot plot = new CategoryPlot(scatterDataset, xAxis, yAxis, renderer);
    JFreeChart boxchart = new JFreeChart(title, new Font("Helvetica", Font.BOLD, 40), plot, true);

    // higher scale factor gives higher resolution
    ChartUtilities.writeScaledChartAsPNG(outStream, boxchart, 800, 1000, 3, 3);
}

From source file:ste.travian.world.WorldChart.java

/**
 * Create the JFreeChart world chart//from  w w w . j  a  v  a2s .com
 * 
 * @param title world title
 * @param dataset world data set
 * 
 */
private void createWorldPlot(String title, XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(LABEL_X_AXIS);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(LABEL_Y_AXIS);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    TileRenderer renderer = new TileRenderer(3, 3);
    renderer.setBaseToolTipGenerator(new TileToolTipGenerator());

    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

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

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

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    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("Information Collected " + 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("informationcollected2" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

/**
 * Creates a new demo./* ww w  .  ja va2s  .  com*/
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumber1(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    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, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + 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("roundnumber1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCategoricalCorrelationPlot.java

private void createChart() {

    String title = "Categorical Plot";

    CategoryDataset chartData = createChartData();

    CategoryAxis domainAxis = new CategoryAxis(null);
    NumberAxis rangeAxis = new NumberAxis(yLabel);
    //BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();

    BoxAndWhiskerCoinPlotRenderer renderer = new BoxAndWhiskerCoinPlotRenderer();
    renderer.setDisplayAllOutliers(true);
    CategoryPlot plot = new CategoryPlot(chartData, domainAxis, rangeAxis, renderer);

    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(45.0 * Math.PI / 180.0));
    catCorrChart = new JFreeChart(title, plot);
    catCorrChart.removeLegend();//w ww.j  a  v a 2s  .  c  o  m
    //renderer.setFillBox(false);
    String cat = (String) chartData.getColumnKey(0);

    //renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setToolTipGenerator(new CategoryToolTipGenerator() {
        public String generateToolTip(CategoryDataset dataset, int series, int item) {
            String tt = "";
            NumberFormat formatter = new DecimalFormat(".####");
            String key = "";
            //String s = formatter.format(-1234.567);  // -001235
            if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                try {
                    String med = formatter.format(ds.getMedianValue(series, item));
                    tt += "Median: " + med + "<br/>";
                    tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                    tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                    tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                    tt += "Max: "
                            + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                            + "<br/>";
                    tt += "Min: "
                            + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                            + "<br/>";
                    //tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                    //tt += "X: " + ds.getValue(series, item).toString()+"<br/>";
                    //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>";
                    key = ds.getRowKeys().get(series).toString();
                } catch (Exception e) {
                }
            }

            return tt;
        }

    });

    //        renderer.setToolTipGenerator(new CategoryToolTipGenerator() {
    //           
    //         public String generateToolTip(CategoryDataset dataset,int series, int item) {
    //            String tt="";
    //            NumberFormat formatter = new DecimalFormat(".####");
    //            String key = "";
    //             //String s = formatter.format(-1234.567);  // -001235
    //            StringBuffer sb = new StringBuffer();
    //             if(dataset instanceof DefaultBoxAndWhiskerCategoryDataset){
    //                DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset)dataset;
    //                try   {
    //                   
    //                   String str;
    //                   str = (String) ds.getColumnKey(item);
    //                   sb.append(str).append(" N=");
    //                   BoxAndWhiskerItem bwitem = ds.getItem(series,item);
    //                   
    //                  str = formatter.format(ds.getMedianValue(series, item));
    //                  sb.append("Median: ").append(str);
    //                  str = formatter.format(ds.getMeanValue(series, item));
    //                  sb.append(" Mean: ").append(str);
    //                  str = formatter.format(ds.getMinRegularValue(series, item));
    //                  sb.append(" Min: ").append(str);
    //                  str = formatter.format(ds.getMaxRegularValue(series, item));
    //                  sb.append(" Max: ").append(str);
    //                  str = formatter.format(ds.getQ1Value(series, item));
    //                  sb.append(" Q1: ").append(str);   
    //                  str = formatter.format(ds.getQ3Value(series, item));
    //                  sb.append(" Q3: ").append(str);
    //                  
    //                }
    //                catch(Exception e) {}
    //             }
    //             
    //            return sb.toString();
    //            
    //         }
    //
    //      });

    plot.setNoDataMessage(null);
}

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

/**
 * Creates a new demo.//  w  ww  .ja  va2s .c  o  m
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumberGlobal(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    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, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + 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("roundGlobalNumber" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

/**
 * Creates a new demo.//from   w ww .jav  a 2 s. c  o m
 *
 * @param title the frame title.
 * @param pf
 */
public MessagesSent1(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Messages Sent");
    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, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Messages Sent " + 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("messagesnumber1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:mediamatrix.gui.JVMMemoryProfilerPanel.java

public JVMMemoryProfilerPanel() {
    initComponents();/*w w  w  . j av a2 s. co m*/
    profiler = new JVMMemoryProfiler(frequency);
    profiler.addListener(new JVMMemoryProfilerListener() {

        @Override
        public void addScore(long t, long f) {
            total.add(new Millisecond(), t);
            free.add(new Millisecond(), f);
        }
    });

    total = new TimeSeries("Total Memory");
    total.setMaximumItemCount(historyCount);
    free = new TimeSeries("Free Memory");
    free.setMaximumItemCount(historyCount);

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(total);
    dataset.addSeries(free);

    final DateAxis domain = new DateAxis("Time");
    final NumberAxis range = new NumberAxis("Memory");
    domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYItemRenderer renderer = new DefaultXYItemRenderer();
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setBaseStroke(new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

    final XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);

    final JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot,
            true);
    chart.setBackgroundPaint(Color.white);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12));

    add(chartPanel, BorderLayout.CENTER);
}