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

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

Introduction

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

Prototype

public void setSeriesVisible(int series, Boolean visible) 

Source Link

Document

Sets the flag that controls whether a series is visible 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./*from www.  j  a v a  2s . 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);
            }
        }
    }

}

From source file:org.openfaces.component.chart.impl.configuration.LineAndShapePropertiesConfigurator.java

private void applyPropertiesToCategoryDataSet(LineAndShapeRenderer renderer, CategoryDataset dataSet,
        LineChartView view, LineProperties lineProperties) {
    DynamicCategoryGenerator dcg = new DynamicCategoryGenerator(view, lineProperties.getDynamicCondition());

    ChartModel chartModel = view.getChart().getModel();
    if (chartModel == null)
        return;// w w  w . j  av a2  s . c  om

    Series[] series = chartModel.getSeries();
    if (series == null)
        return;

    for (int j = 0; j < series.length; j++) {
        if (!dcg.generateCondition(dataSet, j, 0))
            continue;

        Boolean hideSeries = lineProperties.getHideSeries();
        if (hideSeries != null) {
            boolean seriesVisible = !hideSeries;
            renderer.setSeriesVisible(j, seriesVisible);
        }
        Boolean shapesVisible = lineProperties.getShapesVisible();
        if (shapesVisible != null)
            renderer.setSeriesShapesVisible(j, shapesVisible);
        //set style
        Boolean showInLegend = lineProperties.getShowInLegend();
        if (showInLegend != null)
            renderer.setSeriesVisibleInLegend(j, showInLegend);

        StyleObjectModel linePropertiesStyleModel = lineProperties.getStyleObjectModel();
        if (linePropertiesStyleModel != null && linePropertiesStyleModel.getBorder() != null) {
            StyleBorderModel model = linePropertiesStyleModel.getBorder();
            Color color = model.getColor();
            if (color != null)
                renderer.setSeriesPaint(j, color);
            renderer.setSeriesLinesVisible(j, Boolean.valueOf(!model.isNone()));
            renderer.setSeriesStroke(j, PropertiesConverter.toStroke(model));
        }

    }
}