Example usage for org.jfree.chart.axis CategoryAxis setTickMarksVisible

List of usage examples for org.jfree.chart.axis CategoryAxis setTickMarksVisible

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis setTickMarksVisible.

Prototype

public void setTickMarksVisible(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the tick marks are showing and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:storybook.ui.chart.jfreechart.ChartUtil.java

public static void hideDomainAxis(CategoryPlot paramCategoryPlot) {
    CategoryAxis localCategoryAxis = paramCategoryPlot.getDomainAxis();
    localCategoryAxis.setTickMarksVisible(false);
    localCategoryAxis.setTickLabelsVisible(false);
}

From source file:jgnash.ui.budget.BudgetSparkline.java

public static Icon getSparklineImage(final List<BigDecimal> amounts) {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final boolean[] negate = new boolean[amounts.size()];

    for (int i = 0; i < amounts.size(); i++) {
        dataset.addValue(amounts.get(i), CATEGORY, i);
        negate[i] = amounts.get(i).signum() == -1;
    }/*w  ww  . j  a  v  a2s. c  o m*/

    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setAxisLineVisible(false);
    xAxis.setVisible(false);

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setAutoRange(true);
    yAxis.setVisible(false);

    BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(final int row, final int column) {
            return negate[column] ? Color.RED : Color.BLACK;
        }
    };

    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setInsets(INSETS);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(CLEAR);

    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(CLEAR);

    Icon icon = EMPTY_ICON;

    try {
        byte[] image = ENCODER
                .encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
        icon = new ImageIcon(image);
    } catch (IOException ex) {
        Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
    }

    return icon;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java

public static void createCategorySeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) {
    CategoryPlot plot = chart.getCategoryPlot();
    if (chartAxisData.isDomain()) {
        CategoryAxis axis = new CategoryAxis(chartAxisData.getLabel());
        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }/*w w  w .ja v  a  2s  .co  m*/
        if (chartAxisData.isVerticalTickLabels()) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        }
        plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis);
    } else {
        ValueAxis axis = createNumberAxis(chart, chartAxisData);
        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }
        plot.setRangeAxis(axis);
    }
}

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

private void configureDomainAxis(CategoryPlot plot, Font font) {
    CategoryAxis categoryAxis = new CategoryAxis();
    categoryAxis.setTickMarksVisible(true);
    categoryAxis.setTickLabelFont(font);
    categoryAxis.setTickLabelPaint(OUTLINE_COLOR);
    plot.setDomainAxis(categoryAxis);/*from   ww w .j  a  v a 2 s  . c o m*/
    plot.setDomainGridlinesVisible(false);
}

From source file:org.shredzone.bullshitcharts.chart.BarChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/*w  w  w  . jav  a2 s  . c om*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    BarRenderer3D renderer = new BarRenderer3D();

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/* w  w w . ja va  2  s  .  c o  m*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    LineAndShapeRenderer renderer = new LineRenderer3D();
    renderer.setBaseShapesVisible(false);
    //        renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

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

/**
 * Creates a new demo./* ww w  .ja va  2 s . com*/
 */
public IntervalBarChartDemo1() {

    DefaultIntervalCategoryDataset data = null;
    final double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    final double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    data = new DefaultIntervalCategoryDataset(lows, highs);
    data.setCategoryKeys(CATEGORIES);

    final String title = "Strategie Sicherheit";
    final String xTitle = "Zeitraum (in Jahren)";
    final String yTitle = "Performance";
    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.40);
    final DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    final IntervalBarRenderer renderer = new IntervalBarRenderer();
    renderer.setSeriesPaint(0, new Color(51, 102, 153));
    //        renderer.setLabelGenerator(new IntervalCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelPaint(Color.white);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(p);

    final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.white);
    plot.setOrientation(PlotOrientation.VERTICAL);

    this.chart = new JFreeChart(title, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);
}

From source file:bc.ui.swing.charts.BarChart.java

private JFreeChart generateView() {
    JFreeChart ret = ChartFactory.createBarChart(model.getTitle(), model.getDomainAxisLabel(),
            model.getRangeAxisLabel(), ((DefaultCategoryDataset) dataset), PlotOrientation.VERTICAL, true, true,
            false);/* w  w w  .ja v a  2s. co m*/

    ret.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) ret.getPlot();
    plot.setBackgroundPaint(Color.white);

    plot.setDomainGridlinePaint(new Color(200, 200, 200));
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(new Color(200, 200, 200));
    plot.setRangeGridlinesVisible(true);
    BarRenderer barrenderer = (BarRenderer) plot.getRenderer();

    barrenderer.setDrawBarOutline(true);
    barrenderer.setBarPainter(new StandardBarPainter());

    final Color baseColor = new Color(160, 200, 255);
    final DefaultDrawingSupplier otherColors = new DefaultDrawingSupplier();
    plot.setDrawingSupplier(new DefaultDrawingSupplier() {

        boolean first = true;

        @Override
        public Paint getNextPaint() {
            if (first) {
                first = false;
                return baseColor;
            }
            return otherColors.getNextPaint();
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setTickMarksVisible(true);

    return ret;
}

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

/**
 * Creates a new demo.//from w  ww.ja v a2 s .  com
 *
 * @param title  the frame title.
 */
public OverlaidCategoryChartDemo(String title) {

    super(title);
    DefaultIntervalCategoryDataset barData = null;
    double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    barData = new DefaultIntervalCategoryDataset(lows, highs);

    double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } };
    CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals);

    double[][] lineVals = new double[4][5];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            lineVals[i][j] = (Math.random() * 0.56) - 0.18;
        }
    }
    CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals);

    String ctitle = "Strategie Sicherheit";
    String xTitle = "Zeitraum (in Jahren)";
    String yTitle = "Performance";
    CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.4);
    DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    IntervalBarRenderer barRenderer = new IntervalBarRenderer();
    barRenderer.setItemLabelsVisible(Boolean.TRUE);

    CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.black);

    LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES);
    dotRenderer.setItemLabelsVisible(Boolean.TRUE);

    plot.setSecondaryDataset(0, dotData);
    plot.setSecondaryRenderer(0, dotRenderer);

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES);
    plot.setSecondaryDataset(1, lineData);
    plot.setSecondaryRenderer(1, lineRenderer);

    this.chart = new JFreeChart(ctitle, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:uk.ac.lkl.cram.ui.chart.FeedbackChartMaker.java

/**
 * Create a chart from the provided category dataset
 * @return a Chart that can be rendered in a ChartPanel
 *//*  w  w  w . j  a v a  2  s. c om*/
@Override
protected JFreeChart createChart() {
    //Create a vertical bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //Get the font from the platform UI
    Font chartFont = UIManager.getFont("Label.font");
    //Get the plot from the chart
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //Get the renderer from the plot
    BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
    //Set the rendered to use a standard bar painter (nothing fancy)
    barRenderer.setBarPainter(new StandardBarPainter());
    //Set the colours for the bars
    barRenderer.setSeriesPaint(0, PEER_ONLY_COLOR);
    barRenderer.setSeriesPaint(1, TEL_COLOR);
    barRenderer.setSeriesPaint(2, TUTOR_COLOR);
    //Set the tooltip to be series, category and value
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(
            "<html><center>{0} ({2} hours)<br/>Double-click for more</center></html>",
            NumberFormat.getInstance()));
    //Get the category axis (that's the X-axis in this case)
    CategoryAxis categoryAxis = plot.getDomainAxis();
    //Set the font for rendering the labels on the x-axis to be the platform default
    categoryAxis.setLabelFont(chartFont);
    //Hide the tick marks and labels for the x-axis
    categoryAxis.setTickMarksVisible(false);
    categoryAxis.setTickLabelsVisible(false);
    //Set the label for the x-axis
    categoryAxis.setLabel("Feedback to individuals or group");
    //Get the number axis (that's the Y-axis in this case)
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    //Use the same font as the x-axis
    numberAxis.setLabelFont(chartFont);
    //Set the label for the vertical axis
    numberAxis.setLabel("Hours");
    return chart;
}