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.wpi.cs.wpisuitetng.modules.requirementmanager.view.requirements.NewBarChartPanel.java

/**
 * @param dataset the data to be shown by the chart
 * @param title the title of the chart(either status or iteration) @return
 *            the created bar graph/* ww  w .ja v  a2s . c o m*/
 */
private static JFreeChart createChart(CategoryDataset dataset, String title) {
    JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "Name", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

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

    return chart;
}

From source file:grafici.MediciBarChart.java

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

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(titolo, // 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...

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

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

    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    //
    // > http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // 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);

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

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

    return chart;

}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setLowerMargin(0.0D);/*from  w ww  . jav a 2  s  . c om*/
    numberaxis.setUpperMargin(0.0D);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setInverted(true);
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 3.5D, Color.black);
    lookuppaintscale.add(0.5D, Color.green);
    lookuppaintscale.add(1.5D, Color.orange);
    lookuppaintscale.add(2.5D, Color.red);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setForegroundAlpha(0.66F);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo3", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "OK", "Uncertain", "Bad" });
    symbolaxis.setRange(0.5D, 3.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

From source file:org.cyberoam.iview.charts.CustomDomainAxis.java

public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;/*from   w w  w . j av  a2s  . c  o  m*/
    //   DefaultCategoryDataset dataset=null;
    CustomCategoryDataset datasetCustom = null;

    try {
        ReportColumnBean reportColumnBeanX = null;
        ReportColumnBean reportColumnBeanY = null;
        ReportColumnBean reportColumnBeanZ = null;
        GraphBean graphBean = null;

        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBeanX.getDbColumnName();
        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBeanY.getDbColumnName();
        String zColumnDBname = null;

        datasetCustom = new CustomCategoryDataset();
        rsw.beforeFirst();
        String data = "";
        int count = -1;
        Boolean showLegend = false;
        if (graphBean.getZColumnId() == -1) {

            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), "", data);
            }

        } else {
            String zData;
            showLegend = true;
            reportColumnBeanZ = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                    graphBean.getZColumnId());
            zColumnDBname = reportColumnBeanZ.getDbColumnName();
            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                zData = rsw.getString(zColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), zData, data);
                count++;
            }

        }
        chart = ChartFactory.createLineChart("", // chart title
                "", // domain axis label
                "", // range axis label
                datasetCustom, // data
                PlotOrientation.VERTICAL, // orientation
                showLegend, // include legend
                true, // tooltips
                false // urls
        );
        LegendTitle legendTitle = chart.getLegend();
        if (legendTitle != null)
            legendTitle.setItemFont(new Font("Vandara", Font.BOLD, 11));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelInsets(new RectangleInsets(0, 0, 0, 5));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);
        CustomDomainAxis catAxis = new CustomDomainAxis();
        CustomDomainAxis.counter = 0;
        CustomDomainAxis.colCount = datasetCustom.getColumnCount();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setTickLabelInsets(new RectangleInsets(10, 15, 30, 10));
        catAxis.setAxisLineVisible(false);
        catAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(20 * Math.PI / 180));
        plot.setDomainAxis(catAxis);
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        if (count > 0) {
            Color[] colors = null;
            colors = new Color[5];
            colors[0] = new Color(24, 112, 176);
            colors[1] = new Color(168, 192, 232);
            colors[2] = new Color(248, 120, 8);
            colors[3] = new Color(248, 184, 120);
            colors[4] = new Color(152, 216, 136);
            for (int i = 0; i < count && i < colors.length; i++)
                renderer.setSeriesPaint(i, colors[i]);
        }
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("LineChart: " + e.getMessage(), e);
    }
    return chart;
}

From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java

/**
 * Creates a sample chart.//from  w  w w. j  av  a2s  .  co m
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
public static JFreeChart createChart(final CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "X-value", // domain axis label
            "Y-value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, false);
    chart.addSubtitle(new TextTitle("http://www.bupt.edu.cn", new Font("", Font.ITALIC, 10)));
    //   chart.setBackgroundPaint(Color.white);
    //   chart.setBackgroundPaint(Color.getHSBColor(2, 29, 100));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);

    //
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setCategoryMargin(0.1);//
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.10);

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

    chart.getTitle().setFont(new Font("", Font.PLAIN, 16));//

    CategoryAxis domainAxis = plot.getDomainAxis();
    //
    domainAxis.setLabelFont(new Font("", Font.PLAIN, 14));
    //
    domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10));

    //
    rangeAxis.setLabelFont(new Font("", Font.PLAIN, 15));

    chart.getLegend().setItemFont(new Font("", Font.PLAIN, 15));

    return chart;
}

From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java

private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) {
    final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);

    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setNoDataMessage("NO DATA!");

    chart.setBackgroundPaint(new Color(245, 245, 255));
    chart.setBorderPaint(new Color(204, 204, 204));
    chart.setBorderStroke(new BasicStroke(1f));

    final LegendTitle legend = chart.getLegend();
    legend.setWidth(1000);/*from ww w  .  j a  va 2  s . com*/
    legend.setPosition(RectangleEdge.BOTTOM);

    final BlockBorder border = new BlockBorder(new Color(204, 204, 204));
    legend.setBorder(border);

    final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204));
    categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis();

    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();
    renderer.setDrawBarOutline(true);

    final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(itemlabelposition);

    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    renderer.setItemLabelsVisible(true);
    return chart;
}

From source file:gui.MainForm.java

private static JFreeChart create_AMS_DATA_Chart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("AMS??", "", "??", 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:userInterface.cdcRole.OverviewJPanel.java

private static JFreeChart createChart1(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Distribution of Vaccines", "Vaccine", "Quantity",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeCrosshairVisible(true);
    categoryplot.setRangeCrosshairPaint(Color.green);
    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.green, 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:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java

private static JFreeChart createChart(BarGraphDataSeries dataSeries) {
    if (dataSeries == null)
        return null;

    BarGraphDataSeries ds = dataSeries;/*from   w  ww  .  j ava 2  s  .c  o m*/

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(ds.getTitle(), // chart title
            ds.getDomainLabel(), // domain axis label
            ds.getRangeLabel(), // range axis label
            ds.getDataSet(0), // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // 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);

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

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

    ValueRange vr = ds.getRangeValueRanges().get(0);
    if (vr != null) {
        Range range = new Range(vr.getMin() / vr.getScale(), vr.getMax() / vr.getScale());
        rangeAxis.setRange(range);
    }
    return chart;

}

From source file:eu.delving.stats.ChartHelper.java

private static JFreeChart finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    if (colors.length > 0)
        categoryplot.setRenderer(new CustomRenderer(colors));
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemLabelAnchorOffset(9D);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    barrenderer.setMaximumBarWidth(0.05);
    barrenderer.setItemMargin(0.03D);//w  w  w .ja v  a2  s .  co  m
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT,
            -1.5707963267948966D);
    barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
    ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT,
            -1.5707963267948966D);
    barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    categoryaxis.setCategoryMargin(0.25D);
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
}