Example usage for org.jfree.chart.block BlockBorder BlockBorder

List of usage examples for org.jfree.chart.block BlockBorder BlockBorder

Introduction

In this page you can find the example usage for org.jfree.chart.block BlockBorder BlockBorder.

Prototype

public BlockBorder(Paint paint) 

Source Link

Document

Creates a new border with the specified color.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", xydataset, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    LegendTitle legendtitle = new LegendTitle(xyplot);
    legendtitle.setItemFont(new Font("Dialog", 0, 9));
    legendtitle.setBackgroundPaint(new Color(200, 200, 255, 100));
    legendtitle.setFrame(new BlockBorder(Color.white));
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.02D, legendtitle,
            RectangleAnchor.BOTTOM_RIGHT);
    xytitleannotation.setMaxWidth(0.47999999999999998D);
    xyplot.addAnnotation(xytitleannotation);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*  w w w  .  j ava2s  .  c o m*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ValueAxis valueaxis = xyplot.getRangeAxis();
    valueaxis.setLowerMargin(0.34999999999999998D);
    return jfreechart;
}

From source file:org.openfaces.component.chart.impl.helpers.LegendAdapter.java

public LegendAdapter(Plot plot, Chart chart) {
    super(plot);//from  w  ww .j  a  v a2  s . c  o  m
    ChartLegend legend = chart.getLegend();

    setPosition(RectangleEdge.BOTTOM);

    StyleObjectModel cssLegendModel = (legend != null) ? legend.getStyleObjectModel()
            : chart.getStyleObjectModel();

    final boolean chartBackgroundPaintDefined = chart.getChartView().getBackgroundPaint() != null;
    if (chartBackgroundPaintDefined) {
        setBackgroundPaint(chart.getChartView().getBackgroundPaint());
    } else {
        setBackgroundPaint(cssLegendModel.getBackground());
    }

    StyleBorderModel border = cssLegendModel.getBorder();

    if (border != null && !border.isNone()) {
        setBorder(new BlockBorder(border.getColor()));
    } else {
        setBorder(new BlockBorder(cssLegendModel.getBackground()));
    }

    setMargin(cssLegendModel.getMargin(0), cssLegendModel.getMargin(1), cssLegendModel.getMargin(2),
            cssLegendModel.getMargin(3));

    if (legend != null) {
        LegendPosition position = legend.getPosition();
        setPosition(position != null ? position.toRectangleEdge() : RectangleEdge.BOTTOM);
    }

    //from legend labels
    ChartLabels labels = (legend != null) ? legend.getLabels() : null;
    if (labels != null) {
        StyleObjectModel cssLabelsModel = labels.getStyleObjectModel();
        setItemPaint(cssLabelsModel.getColor());
        setItemFont(CSSUtil.getFont(cssLabelsModel));
    } else {
        setItemPaint(cssLegendModel.getColor());
        setItemFont(CSSUtil.getFont(cssLegendModel));
    }

}

From source file:org.openfaces.component.chart.impl.helpers.TextTitleAdapter.java

public TextTitleAdapter(Chart chart) {
    ChartTitle title = chart.getTitle();
    if (title == null || title.getText() == null)
        return;//from w  w w. j  a v a 2 s  .c o  m

    setText(title.getText());

    if (title.getActionExpression() == null && title.getUrl() != null) {
        setURLText(title.getUrl());
    }

    setToolTipText(title.getTooltip());

    StyleObjectModel styleModel = title.getStyleObjectModel();
    if (styleModel != null) {
        setFont(CSSUtil.getFont(styleModel));

        final boolean chartTitlePaintDefined = chart.getChartView().getBackgroundPaint() != null;

        if (chartTitlePaintDefined) {
            setExpandToFitSpace(true);
            setBackgroundPaint(chart.getChartView().getTitlePaint());
        }

        if (styleModel.getBackground() != null && !chartTitlePaintDefined) {
            setBackgroundPaint(styleModel.getBackground());
            setBorder(new BlockBorder(styleModel.getBackground()));
        }

        if (styleModel.getColor() != null) {
            setPaint(styleModel.getColor());
        }

        StyleBorderModel border = styleModel.getBorder();
        if (border != null) {
            if (!border.isNone() && border.getColor() != null) {
                BlockBorder bb = new BlockBorder(border.getColor());
                setBorder(bb);
            }
        }

        setMargin(styleModel.getMargin(0), styleModel.getMargin(1), styleModel.getMargin(2),
                styleModel.getMargin(3));
    }

    setNotify(true);
}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.0D);//from  ww  w.  java  2 s  .  c o m
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setAxisLinePaint(Color.white);
    numberaxis.setTickMarkPaint(Color.white);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setAxisLinePaint(Color.white);
    numberaxis1.setTickMarkPaint(Color.white);
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    GrayPaintScale graypaintscale = new GrayPaintScale(-2D, 1.0D);
    xyblockrenderer.setPaintScale(graypaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setOutlinePaint(Color.blue);
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Scale");
    numberaxis2.setAxisLinePaint(Color.white);
    numberaxis2.setTickMarkPaint(Color.white);
    numberaxis2.setTickLabelFont(new Font("Dialog", 0, 7));
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(new GrayPaintScale(), numberaxis2);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    paintscalelegend.setFrame(new BlockBorder(Color.red));
    paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
    paintscalelegend.setStripWidth(10D);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setBackgroundPaint(new Color(120, 120, 180));
    jfreechart.addSubtitle(paintscalelegend);
    jfreechart.setBackgroundPaint(new Color(180, 180, 250));
    return jfreechart;
}

From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java

/**
 * Creates a chart./*  ww w . ja v  a 2 s.c o  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            false, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(200, 200, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.BOTTOM);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, RectangleAnchor.BOTTOM_RIGHT);

    ta.setMaxWidth(0.48);
    plot.addAnnotation(ta);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setLowerMargin(0.35);
    return chart;

}

From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java

private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) {
    final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);

    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setNoDataMessage("NO DATA!");

    chart.setBackgroundPaint(new Color(245, 245, 255));
    chart.setBorderPaint(new Color(204, 204, 204));
    chart.setBorderStroke(new BasicStroke(1f));

    final LegendTitle legend = chart.getLegend();
    legend.setWidth(1000);//from www .  j a v a  2 s .c  om
    legend.setPosition(RectangleEdge.BOTTOM);

    final BlockBorder border = new BlockBorder(new Color(204, 204, 204));
    legend.setBorder(border);

    final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204));
    categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis();

    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();
    renderer.setDrawBarOutline(true);

    final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(itemlabelposition);

    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    renderer.setItemLabelsVisible(true);
    return chart;
}

From source file:y.graphs.ChartHelperELF.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );//  w w  w .  j a v a  2 s  . com

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundELF());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //            renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //        rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:y.graphs.ChartHelperSRB.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );/*from  ww  w .  ja  v  a2  s . com*/

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundSRB());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //          renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //      rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:grafix.graficos.eixos.Eixo.java

private void incluirLegenda(final XYPlot plot) {
    if (isLegenda()) {
        LegendTitle lt = new LegendTitle(plot);
        lt.setItemFont(new Font("Dialog", Font.PLAIN, 11));
        lt.setBackgroundPaint(new Color(255, 255, 255, 100));
        lt.setBorder(new BlockBorder(new Color(180, 180, 180)));
        lt.setPosition(RectangleEdge.TOP);
        XYTitleAnnotation ta = new XYTitleAnnotation(0.01, 0.98, lt, RectangleAnchor.TOP_LEFT);
        ta.setMaxWidth(0.48);//w  w w. j  av  a  2  s  . com
        plot.addAnnotation(ta);
    }
}

From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java

private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints,
        XYDataset xyData) {/*  w ww .  j a v  a 2  s . c om*/
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0], maxs[0]);

    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);

    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    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.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}