Example usage for org.jfree.chart.plot CategoryPlot setRangeCrosshairStroke

List of usage examples for org.jfree.chart.plot CategoryPlot setRangeCrosshairStroke

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot setRangeCrosshairStroke.

Prototype

public void setRangeCrosshairStroke(Stroke stroke) 

Source Link

Document

Sets the pen-style (Stroke) used to draw the range crosshair (if visible), and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.WinLose.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createBarChart(name, null, null, dataset, PlotOrientation.VERTICAL, legend,
            false, false);/*from  ww w  . ja v a 2 s  . com*/
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(color);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    plot.setRangeCrosshairPaint(color.BLACK);

    // customize axes 
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setCategoryMargin(0.2);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    rangeAxis.setRange(new Range(-(barHeight + 0.2), (barHeight + 0.2)));

    // customize renderer 
    MyBarRendererThresholdPaint renderer = new MyBarRendererThresholdPaint(useTargets, thresholds, dataset,
            timeSeries, nullValues, bottomThreshold, color);

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.#")) {
                    public String generateLabel(CategoryDataset dataset, int row, int column) {
                        if (dataset.getValue(row, column) == null
                                || dataset.getValue(row, column).doubleValue() == 0)
                            return "";
                        String columnKey = (String) dataset.getColumnKey(column);
                        int separator = columnKey.indexOf('-');
                        String month = columnKey.substring(0, separator);
                        String year = columnKey.substring(separator + 1);
                        int monthNum = Integer.parseInt(month);
                        if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                            if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                                return "";

                            Calendar calendar = Calendar.getInstance();
                            calendar.set(Calendar.MONTH, monthNum - 1);
                            SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                            return dataFormat.format(calendar.getTime());
                        } else
                            return "" + monthNum;
                    }
                });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4 || wlt_mode.doubleValue() == 5) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        plot.setFixedLegendItems(collection);
    }

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth);
    }
    //renderer.setSeriesPaint(0, Color.BLUE); 
    plot.setRenderer(renderer);

    logger.debug("OUT");
    if (mainThreshold == null)
        return null;
    return chart;

}