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:org.jfree.chart.demo.XYBlockChartDemo1.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.0D);//w  ww  .j  a  va  2s  .co m
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setAxisLinePaint(Color.white);
    numberaxis.setTickMarkPaint(Color.white);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setAxisLinePaint(Color.white);
    numberaxis1.setTickMarkPaint(Color.white);
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    GrayPaintScale graypaintscale = new GrayPaintScale(-2D, 1.0D);
    xyblockrenderer.setPaintScale(graypaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setOutlinePaint(Color.blue);
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Scale");
    numberaxis2.setAxisLinePaint(Color.white);
    numberaxis2.setTickMarkPaint(Color.white);
    numberaxis2.setTickLabelFont(new Font("Dialog", 0, 7));
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(new GrayPaintScale(), numberaxis2);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    paintscalelegend.setFrame(new BlockBorder(Color.red));
    paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
    paintscalelegend.setStripWidth(10D);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setBackgroundPaint(new Color(120, 120, 180));
    jfreechart.addSubtitle(paintscalelegend);
    jfreechart.setBackgroundPaint(new Color(180, 180, 250));
    return jfreechart;
}

From source file:org.matsim.contrib.util.timeprofile.TimeProfileCharts.java

public static JFreeChart chartProfile(DefaultTableXYDataset dataset, ChartType type) {
    JFreeChart chart;/*from  w  w  w  . ja v a2 s  . co m*/
    switch (type) {
    case Line:
        chart = ChartFactory.createXYLineChart("TimeProfile", "Time [h]", "Values", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        break;

    case StackedArea:
        chart = ChartFactory.createStackedXYAreaChart("TimeProfile", "Time [h]", "Values", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        break;

    default:
        throw new IllegalArgumentException();
    }

    XYPlot plot = chart.getXYPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRange(true);

    XYItemRenderer renderer = plot.getRenderer();
    for (int s = 0; s < dataset.getSeriesCount(); s++) {
        renderer.setSeriesStroke(s, new BasicStroke(2));
    }

    return chart;
}

From source file:org.codehaus.mojo.chronos.chart.ChartUtil.java

static XYPlot newPlot(XYDataset dataset, String label, boolean forceIncludeZero) {
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer();
    NumberAxis numberaxis = new NumberAxis(label);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(forceIncludeZero);
    return new XYPlot(dataset, null, numberaxis, standardxyitemrenderer);
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Mouseover Demo 1", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    MyBarRenderer mybarrenderer = new MyBarRenderer();
    mybarrenderer.setDrawBarOutline(true);
    categoryplot.setRenderer(mybarrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    mybarrenderer.setSeriesPaint(0, gradientpaint);
    mybarrenderer.setSeriesPaint(1, gradientpaint1);
    mybarrenderer.setSeriesPaint(2, gradientpaint2);
    return jfreechart;
}

From source file:userInterface.ManufactureRole.DecisionChartJPanel.java

private static JFreeChart createChart1(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Vaccine Sales", "Vaccine", "quantity", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeCrosshairVisible(true);
    categoryplot.setRangeCrosshairPaint(Color.blue);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
    return jfreechart;
}

From source file:org.codehaus.mojo.chronos.chart.ChartUtil.java

public static XYPlot setupXYPlot(JFreeChart chart, DateFormat dateFormat) {
    XYPlot plot = chart.getXYPlot();//from w  w  w  .j a  v a2s .  co m

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(dateFormat);

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

From source file:wef.articulab.view.ui.BNCategoryPlot.java

/**
 * Creates a chart./*from  w w  w .  ja  v  a  2s  .c o  m*/
 *
 * @return A chart.
 */
private static JFreeChart createChart() {

    dataset = createDataset();
    NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis1, renderer);
    subplot.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Time");
    CombinedCategoryPlot plot = new CombinedCategoryPlot(domainAxis, new NumberAxis("Activation"));
    plot.add(subplot);

    return new JFreeChart("Social Reasoner Plot", new Font("SansSerif", Font.BOLD, 12), plot, true);
}

From source file:org.jfree.chart.swt.demo.SWTBarChartDemo1.java

/**
 * Creates a sample chart./*w  ww. j  a  v a  2 s .c  o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("SWTBarChartDemo1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset);

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

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

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

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

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}

From source file:eu.delving.sip.base.ReportChartHelper.java

private static JPanel finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangePannable(true);/*from   www.  j  a  va  2s.  c o m*/
    if (colors.length > 0)
        plot.setRenderer(new CustomRenderer(colors));
    BarRenderer bar = (BarRenderer) plot.getRenderer();
    bar.setItemLabelAnchorOffset(9D);
    bar.setBaseItemLabelsVisible(true);
    bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bar.setMaximumBarWidth(0.05);
    bar.setItemMargin(0.03D);
    bar.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D));
    bar.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D));
    CategoryAxis x = plot.getDomainAxis();
    x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    x.setCategoryMargin(0.25D);
    x.setUpperMargin(0.02D);
    x.setLowerMargin(0.02D);
    NumberAxis y = (NumberAxis) plot.getRangeAxis();
    y.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    y.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return new ChartPanel(chart);
}

From source file:org.jfree.experimental.chart.swt.demo.SWTBarChartDemo1.java

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

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("SWTBarChartDemo1", // chart title
            "Category", // 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...

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

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

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

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}