Example usage for org.jfree.chart.renderer.category LineAndShapeRenderer setBaseSeriesVisible

List of usage examples for org.jfree.chart.renderer.category LineAndShapeRenderer setBaseSeriesVisible

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category LineAndShapeRenderer setBaseSeriesVisible.

Prototype

public void setBaseSeriesVisible(boolean visible) 

Source Link

Document

Sets the base visibility and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * The 'ewtr' tag is an Eastwood extension that draws a trend line over a
 * chart, using data that has been added to a secondary dataset using the
 * 'ewd2' tag./*  w  ww  .  ja v  a 2  s. co m*/
 *
 * @param params  the chart parameters;
 * @param chart  the chart under construction (will be updated by this
 *         method if necessary).
 */
public static void processEWTR(Map params, JFreeChart chart) {
    // the 'ewtr' arguments are:
    // - <seriesIndex> : the index of the series in the secondary dataset;
    // - <colour> : the colour;
    // - <lineThickness> : the line thickness;
    String[] ewtrStr = (String[]) params.get("ewtr");
    if (ewtrStr != null) {
        String[] atts = ewtrStr[0].split(",");
        int series = Integer.parseInt(atts[0]);
        Color color = parseColor(atts[1]);
        float lineWidth = Float.parseFloat(atts[2]);
        Plot plot = chart.getPlot();
        if (plot instanceof CategoryPlot) {
            CategoryPlot cp = (CategoryPlot) plot;
            if (cp.getDataset(1) != null) {
                LineAndShapeRenderer r = new LineAndShapeRenderer(true, false);
                r.setBaseSeriesVisible(false);
                r.setSeriesVisible(series, Boolean.TRUE);
                r.setSeriesPaint(series, color);
                r.setSeriesStroke(series, new BasicStroke(lineWidth));
                cp.setRenderer(1, r);

                cp.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
            }
        } else if (plot instanceof XYPlot) {
            XYPlot xp = (XYPlot) plot;
            if (xp.getDataset(1) != null) {
                XYLineAndShapeRenderer r = new XYLineAndShapeRenderer(true, false);
                r.setBaseSeriesVisible(false);
                r.setSeriesVisible(series, Boolean.TRUE);
                r.setSeriesPaint(series, color);
                r.setSeriesStroke(series, new BasicStroke(lineWidth));
                xp.setRenderer(1, r);
                xp.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
            }
        }
    }

}