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

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

Introduction

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

Prototype

public void setNegativeArrowVisible(boolean visible) 

Source Link

Document

Sets a flag that controls whether or not the axis lines has an arrow drawn that points in the negative direction for the axis, and sends an AxisChangeEvent to all registered listeners.

Usage

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;
    }//from ww w .ja va 2s. co 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.maltcms.common.charts.ui.XYChartComponentOpenAction.java

@Override
public void actionPerformed(ActionEvent e) {
    Task t = RequestProcessor.getDefault().create(new Runnable() {
        @Override/*from w ww.j  a  v a2s  . co m*/
        public void run() {
            final Numeric1DDataset<Point2D> dataset = createDataset();
            final XYChartBuilder builder = new XYChartBuilder();
            XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            renderer.setBaseItemLabelsVisible(true);
            renderer.setDefaultEntityRadius(50);
            NumberAxis domain = new NumberAxis("x-axis");
            domain.setLowerBound(-100);
            domain.setUpperBound(1000);
            domain.setLowerMargin(0.1);
            domain.setUpperMargin(0.1);
            domain.setPositiveArrowVisible(true);
            domain.setNegativeArrowVisible(true);
            builder.xy(dataset).renderer(renderer).domainAxis(domain).useBuffer(false).minimumDrawSize(400, 300)
                    .preferredDrawSize(800, 600).plot().chart("Sample plot").createLegend(true);
            invokeLater(new Runnable() {
                @Override
                public void run() {
                    TopComponent tc = WindowManager.getDefault().findTopComponent("navigatorTC");
                    if (tc != null) {
                        tc.open();
                    }
                }
            });
            invokeLater(new Runnable() {

                @Override
                public void run() {
                    XYChartTopComponent<Point2D> xytc = new XYChartTopComponent<>(Point2D.class, dataset,
                            builder);
                    xytc.open();
                    xytc.requestActive();
                }
            });

        }
    });
    RequestProcessor.getDefault().post(t);
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a SparkLine Time Area Chart.
 * @param key//  w  ww.ja  va 2s.c  o m
 * @param stats
 * @param startTime
 * @param endTime
 * @return chart
 */
private JFreeChart generateSparklineAreaChart(String key, String color, Statistic[] stats, long startTime,
        long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();

    XYDataset dataset = populateData(key, stats, startTime, endTime, dataPoints);

    JFreeChart chart = ChartFactory.createXYAreaChart(null, // chart title
            null, // xaxis label
            null, // yaxis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(1.0f);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);

    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);

    NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();

    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);

    NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);

    return chart;
}