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

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

Introduction

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

Prototype

public void setStandardTickUnits(TickUnitSource source) 

Source Link

Document

Sets the source for obtaining standard tick units for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL,//from  w w w. jav  a2s  .  c  o  m
            // !legendPanelOn,
            false, // no legend
            true, false);

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:graphs.ResultsGraphs.java

/**
 * Creates a sample chart./*from  w  ww  .  ja  va 2 s. c o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Mashup Language Sentiment Algorithm Performance ", // chart title
            "Performance Metric", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:j2se.jfreechart.barchart.BarChartDemo2.java

/**
 * Creates a chart./*w  w  w .jav a  2s  .c  o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 2", // chart title
            "Category", // domain axis label
            "Score (%)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.lightGray);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * Creates a chart.//  ww  w  .  j a v  a2 s. co m
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 2", // chart title
            "Category", // domain axis label
            "Score (%)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.lightGray);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.KaplanMeierPlot.java

private void createChart(XYDataset dataset) {
    //Create the chart, dropping in the data set
    JFreeChart chart = ChartFactory.createXYLineChart("", "Days in Study", "Probability of Survival", dataset,
            PlotOrientation.VERTICAL, false, //legend
            true, //tooltips
            false//urls
    );/*from   w ww. j  a v  a 2 s .co  m*/
    LegendTitle legend = chart.getLegend();
    XYPlot plot = (XYPlot) chart.getPlot();
    /********************************************************
     * IMPORTANT:
     * Ideally I would create the actual Renderer settings for
     * the at the time I start to march through the 
     * KaplanMeierPlotPointSeriesSets, adding them to the actual
     * Data Set that is going to be going into the Chart plotter.
     * But you have no idea how they are going to be sitting in
     * the Plot dataset so there is no guarantee that setting the
     * renderer based on a supposed index will actually work. In fact
     * it didn't work when I wrote this.
     * 
     */
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < finalDataCollection.getSeriesCount(); i++) {
        KaplanMeierPlotPointSeries kmSeries = (KaplanMeierPlotPointSeries) finalDataCollection.getSeries(i);
        if (kmSeries.getType() == SeriesType.CENSOR) {
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, true);
        } else if (kmSeries.getType() == SeriesType.PROBABILITY) {
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesVisible(i, false);

        } else {
            //don't show this set as it is not a known type
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, false);
        }
        renderer.setSeriesPaint(i, getKMSetColor(kmSeries.getKey(), kmSeries.getType()), true);
    }

    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    plot.setRenderer(renderer);
    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    rangeAxis.setAutoRange(true);
    rangeAxis.setRange(0.0, 1.0);
    kmChart = chart;
}

From source file:org.sonar.plugins.core.charts.DistributionAreaChart.java

@Override
protected Plot getPlot(ChartParameters params) {
    DefaultCategoryDataset dataset = createDataset(params);

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryMargin(0.0);//from ww w  .  j  a  v  a2  s .c om
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance(params.getLocale()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    AreaRenderer renderer = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    plot.setForegroundAlpha(0.5f);
    plot.setDomainGridlinesVisible(true);
    configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));
    return plot;
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo2.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, // !legendPanelOn,
            true, false);/*from w w  w.j a  v  a 2s  .  c  o m*/

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // setXSummary(dataset);  //X  is time
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:eu.choreos.chart.XYChart.java

private JFreeChart createChart(XYDataset dataset, String chartTitle) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "Execution size", // domain axis label
            "Range", // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from www  . j av  a2s  .co m*/

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    return chart;
}

From source file:gui.DendrogramChart.java

ChartPanel getChartPanel(Dendrogram d, boolean log) {
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Similarity", "No. of Groups", null,
            PlotOrientation.VERTICAL, true, true, false);

    setChartData(chart, log);/*www . j  ava 2 s  .  c  o  m*/

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    chart.setRenderingHints(rh);
    chart.removeLegend();

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(255, 255, 220));
    plot.setDomainGridlinePaint(new Color(128, 128, 128));
    plot.setRangeGridlinePaint(new Color(128, 128, 128));
    if (log == false) {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setLowerBound(0);
        rangeAxis.setNumberFormatOverride(new DecimalFormat("0"));
        rangeAxis.setLabelFont(Prefs.labelFont);
    } else {
        // LogarithmicAxis logXAxis = new LogarithmicAxis("Similarity");
        // logXAxis.setAllowNegativesFlag(true);
        LogarithmicAxis logYAxis = new LogarithmicAxis("No. Of Groups");
        logYAxis.setAllowNegativesFlag(false);

        // plot.setDomainAxis(logXAxis);
        plot.setRangeAxis(logYAxis);
    }

    ChartPanel chartPanel = new ChartPanel(chart);
    // chartPanel.setPopupMenu(null);
    return chartPanel;
}

From source file:com.intel.stl.ui.configuration.view.SC2VLNTMTBarChartPanel.java

@Override
public void initComponents() {
    dataset = new XYSeriesCollection();

    JFreeChart chart = ComponentFactory.createXYBarChart(K1105_SC.getValue(), K1110_VLNT.getValue(), dataset,
            (XYItemLabelGenerator) null);

    XYPlot plot = chart.getXYPlot();//from w w  w  .ja  v a 2s.c  om
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    final String scLabel = "<html>" + K1105_SC.getValue() + ": ";
    final String vlntLabel = "<br>" + K1110_VLNT.getValue() + ": ";

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarAlignmentFactor(0);
    renderer.setMargin(0.2);

    renderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int arg1, int arg2) {
            int scNum = (int) dataset.getXValue(arg1, arg2);
            int vlntCount = (int) dataset.getYValue(arg1, arg2);
            return scLabel + scNum + vlntLabel + vlntCount + "</html>";
        }
    });
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(PREFERRED_CHART_SIZE);
    propsPanel.add(chartPanel);
}