Example usage for org.jfree.chart.title PaintScaleLegend setAxisOffset

List of usage examples for org.jfree.chart.title PaintScaleLegend setAxisOffset

Introduction

In this page you can find the example usage for org.jfree.chart.title PaintScaleLegend setAxisOffset.

Prototype

public void setAxisOffset(double offset) 

Source Link

Document

Sets the offset between the axis and the paint strip and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java

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

    DateAxis xAxis = new DateAxis(yLabel);
    xAxis.setLowerMargin(0.0);//from   w  w  w.ja v a 2  s .co m
    xAxis.setUpperMargin(0.0);
    xAxis.setInverted(false);
    xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
    if (dateAutoRange) {
        xAxis.setAutoRange(true);
    } else {
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter);
        xAxis.setTickUnit(unit);
    }

    if (dateMin != null && dateMax != null) {
        xAxis.setRange(dateMin, addDay(dateMax));
    } else {
        xAxis.setRange(minDateFound, addDay(maxDateFound));
    }

    //      Calendar c=new GregorianCalendar();
    //      c.set(9 + 2000, Calendar.JANUARY, 1);
    //      java.util.Date minima=c.getTime();
    //      Calendar c1=new GregorianCalendar();
    //      c1.set(9 + 2000, Calendar.FEBRUARY, 1);
    //      java.util.Date massima=c1.getTime();

    NumberAxis yAxis = new NumberAxis(xLabel);
    yAxis.setUpperMargin(0.0);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setRange(hourMin, hourMax);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(BLOCK_HEIGHT);
    // one block for each minute!
    renderer.setBlockHeight(0.017);
    //renderer.setBlockWidth(1);
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);

    //      MyXYItemLabelGenerator my=new MyXYItemLabelGenerator();
    //      renderer.setItemLabelsVisible(null);
    //      renderer.setSeriesItemLabelGenerator(0, my);
    //      renderer.setSeriesItemLabelsVisible(0, true);

    //      XYTextAnnotation annotation1 = new XYTextAnnotation(
    //      "P_",1.2309372E12, 14.3);
    //      XYTextAnnotation annotation2 = new XYTextAnnotation(
    //      "P_",1.2308508E12, 16.3);

    for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) {
        String annotationCode = (String) iterator.next();
        AnnotationBlock annotationBlock = annotations.get(annotationCode);
        XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(),
                annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition());
        if (styleAnnotation != null) {
            xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize()));
            xyAnnotation.setPaint(styleAnnotation.getColor());
        } else {
            xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8));
            xyAnnotation.setPaint(Color.BLACK);
        }

        xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
        renderer.addAnnotation(xyAnnotation);
    }

    logger.debug("Annotation set");

    LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color);
    String[] labels = new String[ranges.size() + 1];
    labels[0] = "";

    // ******************** SCALE ****************************
    for (Iterator iterator = ranges.iterator(); iterator.hasNext();) {
        RangeBlocks range = (RangeBlocks) iterator.next();
        Integer index = patternRangeIndex.get(range.getPattern());
        Color color = range.getColor();
        if (color != null) {
            //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);         
            Paint colorTransparent = null;
            if (addTransparency == true) {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);
            } else {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue());
            }
            paintScale.add(index + 0.5, colorTransparent);
        }
        //String insertLabel="            "+range.getLabel();
        String insertLabel = range.getLabel();
        labels[index + 1] = insertLabel;
    }
    renderer.setPaintScale(paintScale);

    SymbolAxis scaleAxis = new SymbolAxis(null, labels);
    scaleAxis.setRange(0.5, ranges.size() + 0.5);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);

    org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setMargin(new RectangleInsets(3, 10, 3, 10));
    psl.setPosition(RectangleEdge.BOTTOM);
    psl.setAxisOffset(5.0);
    // ******************** END SCALE ****************************

    logger.debug("Scale Painted");

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    logger.debug("Plot set");

    JFreeChart chart = new JFreeChart(name, plot);
    if (styleTitle != null) {
        TextTitle title = setStyleTitle(name, styleTitle);
        chart.setTitle(title);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(psl);

    logger.debug("OUT");

    return chart;

}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

protected void resetRenderer(final IScope scope, final String serieid) {
    final XYBlockRenderer newr = (XYBlockRenderer) this.getOrCreateRenderer(scope, serieid);

    // newr.setSeriesStroke(0, new BasicStroke(0));
    final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid);

    if (myserie.getMycolor() != null) {
        newr.setSeriesPaint(0, myserie.getMycolor());
    }//from   w w w. j  a  va  2s  . c  om
    if (myserie.getSValues(scope).size() > 0) {
        final double maxval = Collections.max(myserie.getSValues(scope));
        final double minval = Collections.min(myserie.getSValues(scope));
        Color cdeb = new Color(0, 0, 0, 0);
        if (myserie.getMyMincolor() != null)
            cdeb = myserie.getMyMincolor();
        Color cend = new Color(0.9f, 0.9f, 0.9f, 1.0f);
        if (myserie.getMycolor() != null)
            cend = myserie.getMycolor();

        LookupPaintScale paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, cend);
        if (myserie.getMyMedcolor() != null)
            paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, myserie.getMyMedcolor(), cend);

        newr.setPaintScale(paintscale);

        final NumberAxis scaleAxis = new NumberAxis(myserie.getName());
        scaleAxis.setAxisLinePaint(this.axesColor);
        scaleAxis.setTickMarkPaint(this.axesColor);
        scaleAxis.setTickLabelFont(this.getTickFont());
        scaleAxis.setRange(minval, maxval);
        scaleAxis.setAxisLinePaint(axesColor);
        scaleAxis.setLabelFont(getLabelFont());
        if (textColor != null) {
            scaleAxis.setLabelPaint(textColor);
            scaleAxis.setTickLabelPaint(textColor);
        }
        if (!this.getXTickValueVisible(scope)) {
            scaleAxis.setTickMarksVisible(false);
            scaleAxis.setTickLabelsVisible(false);

        }

        final PaintScaleLegend legend = new PaintScaleLegend(paintscale, scaleAxis);
        legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        legend.setAxisOffset(5.0);
        // legend.setMargin(new RectangleInsets(5, 5, 5, 5));
        // legend.setFrame(new BlockBorder(Color.red));
        // legend.setPadding(new RectangleInsets(10, 10, 10, 10));
        // legend.setStripWidth(10);
        legend.setPosition(RectangleEdge.RIGHT);
        legend.setBackgroundPaint(this.backgroundColor);
        // ArrayList<PaintScaleLegend> caxe=new
        // ArrayList<PaintScaleLegend>();
        // caxe.add(legend);
        // chart.setSubtitles(caxe);
        if (!this.series_label_position.equals("none"))
            chart.addSubtitle(legend);

    }
}