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

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

Introduction

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

Prototype

public static TickUnitSource createIntegerTickUnits() 

Source Link

Document

Returns a collection of tick units for integer values.

Usage

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

public static JFreeChart createChart(CategoryDataset acategorydataset[]) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects",
            acategorydataset[0], PlotOrientation.VERTICAL, true, true, false);
    jfreechart.addSubtitle(new TextTitle("By Programming Language"));
    jfreechart.addSubtitle(new TextTitle("As at 5 March 2003"));
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setLowerMargin(0.02D);/*from w ww . ja va 2s .  c  o m*/
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    NumberAxis numberaxis1 = new NumberAxis("Percent");
    numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance());
    categoryplot.setRangeAxis(1, numberaxis1);
    categoryplot.setDataset(1, acategorydataset[1]);
    categoryplot.setRenderer(1, lineandshaperenderer);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Category Marker Demo 1", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryMarker categorymarker = new CategoryMarker("Category 4", Color.blue, new BasicStroke(1.0F));
    categorymarker.setDrawAsLine(true);/*from  www . ja  v  a2  s  .  c  om*/
    categorymarker.setLabel("Marker Label");
    categorymarker.setLabelFont(new Font("Dialog", 0, 11));
    categorymarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    categorymarker.setLabelOffset(new RectangleInsets(2D, 5D, 2D, 5D));
    categoryplot.addDomainMarker(categorymarker, Layer.BACKGROUND);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Category Marker Demo 2", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryMarker categorymarker = new CategoryMarker("Category 4", new Color(0, 0, 255, 25),
            new BasicStroke(1.0F));
    categorymarker.setDrawAsLine(false);
    categorymarker.setAlpha(1.0F);//w  w w  .  j  a v a 2s.  co  m
    categorymarker.setLabel("Marker Label");
    categorymarker.setLabelFont(new Font("Dialog", 0, 11));
    categorymarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    categorymarker.setLabelOffset(new RectangleInsets(2D, 5D, 2D, 5D));
    categoryplot.addDomainMarker(categorymarker, Layer.BACKGROUND);
    return jfreechart;
}

From source file:playground.thibautd.utils.charts.XYChartUtils.java

/**
 * Sets the X axis of an XYPlot chart to a {@link NumberAxis}
 * with integer values.//from   ww w.j ava  2 s  .c om
 */
public static void integerXAxis(final JFreeChart chart) {
    ValueAxis axis = (chart.getXYPlot()).getDomainAxis();
    NumberAxis numberAxis;
    if (axis instanceof NumberAxis) {
        numberAxis = (NumberAxis) axis;
    } else {
        numberAxis = new NumberAxis();
        (chart.getXYPlot()).setDomainAxis(numberAxis);
    }

    numberAxis.setTickUnit((NumberTickUnit) NumberAxis.createIntegerTickUnits().getCeilingTickUnit(1d));
    numberAxis.setAutoRangeIncludesZero(false);
}

From source file:ch.zhaw.ias.dito.ui.util.BlockPlotPanel.java

public BlockPlotPanel(Matrix m, double lowerBound, double upperBound) {
    super(new BorderLayout());
    NumberAxis xAxis = new NumberAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(1.0);//www. j a va  2s  .co  m
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(1.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            XYZDataset xyzDataset = (XYZDataset) dataset;
            double x = xyzDataset.getXValue(series, item);
            double y = xyzDataset.getYValue(series, item);
            double z = xyzDataset.getZValue(series, item);
            return ("X=" + x + ", Y=" + y + ", Z=" + z);
        }
    });
    PaintScale scale = new ColorPaintScale(lowerBound, upperBound);
    renderer.setPaintScale(scale);
    ValueAxis axis = new NumberAxis();
    axis.setLowerBound(scale.getLowerBound());
    axis.setUpperBound(scale.getUpperBound());
    PaintScaleLegend legend = new PaintScaleLegend(scale, axis);
    legend.setMargin(new RectangleInsets(10, 10, 10, 10));
    legend.setPosition(RectangleEdge.RIGHT);

    MatrixXYDataset dataset = new MatrixXYDataset(m);
    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    chart = new JFreeChart(plot);
    chart.removeLegend();
    chart.addSubtitle(legend);
    chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDisplayToolTips(true);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:org.csml.tommo.sugar.heatmap.MeanQualityMatrixChart.java

public static MeanQualityMatrixChart createNiceChart(MeanQualityMatrixDataset dataset, PaintScale paintScale) {

    Rectangle range = dataset.getMeanQualityMatrix().getRange();
    String xLabel = "X from " + range.x + " to " + (range.x + range.width);
    String yLabel = "Y from " + range.y + " to " + (range.y + range.height);

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setTickLabelsVisible(true);/*w  ww  .j ava2 s.  c  o m*/
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setTickLabelsVisible(true);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);

    MeanQualityMatrixChart chart = createChart(dataset, xAxis, yAxis, paintScale);

    // draw paint scale legend
    chart.setPaintScaleLegend(paintScale);

    return chart;
}

From source file:org.csml.tommo.sugar.heatmap.MappingQualityMatrixChart.java

public static MappingQualityMatrixChart createNiceChart(MappingQualityMatrixDataset dataset,
        PaintScale paintScale) {/*from ww  w  .  j a  v  a 2  s .  c  o  m*/

    Rectangle range = dataset.getMappingQualityMatrix().getRange();
    String xLabel = "X from " + range.x + " to " + (range.x + range.width);
    String yLabel = "Y from " + range.y + " to " + (range.y + range.height);

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setTickLabelsVisible(true);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setTickLabelsVisible(true);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);

    MappingQualityMatrixChart chart = createChart(dataset, xAxis, yAxis, paintScale);

    // draw paint scale legend
    chart.setPaintScaleLegend(paintScale);

    return chart;
}

From source file:eu.kprod.gui.chart.MwChartFactory.java

public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) {
    final JFreeChart chart;

    chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true);

    chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));
    chart.setBorderVisible(false);/*ww w . j a  v  a  2s.  c o m*/
    final XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));

    plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS"));
    axis.setAxisLineVisible(false);
    axis.setTickLabelsVisible(false);
    axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    // force integer display
    final ValueAxis va = plot.getRangeAxis();
    va.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    //        va.setRange(-280,280);
    //        va.setFixedAutoRange(560);
    //        va.setLowerBound(-280);
    //        va.setUpperBound(280);
    //        va.setAutoRange(false);
    va.setRangeWithMargins(-280, 280);

    final MwChartPanel chartPanel = new MwChartPanel(chart, conf);
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);

    return chartPanel;

}

From source file:org.multiwii.swingui.gui.chart.MwChartFactory.java

public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) {
    final JFreeChart chart;

    chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true);

    chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));
    chart.setBorderVisible(false);/*from  www  . j a  va  2  s  .  c  om*/
    final XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));

    plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS"));
    axis.setAxisLineVisible(false);
    axis.setTickLabelsVisible(false);
    axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    // force integer display
    final ValueAxis va = plot.getRangeAxis();
    va.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    // va.setRange(-280,280);
    // va.setFixedAutoRange(560);
    // va.setLowerBound(-280);
    // va.setUpperBound(280);
    // va.setAutoRange(false);
    va.setRangeWithMargins(-280, 280);

    final MwChartPanel chartPanel = new MwChartPanel(chart, conf);
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);

    return chartPanel;

}

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;
}