Example usage for org.jfree.chart.renderer.xy XYAreaRenderer setUseFillPaint

List of usage examples for org.jfree.chart.renderer.xy XYAreaRenderer setUseFillPaint

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYAreaRenderer setUseFillPaint.

Prototype

public void setUseFillPaint(boolean use) 

Source Link

Document

Sets the flag that controls whether or not the series fill paint is used to fill the area under the line and sends a RendererChangeEvent to all listeners.

Usage

From source file:edu.fullerton.ldvservlet.SrcList.java

private PageItem makePlots(ArrayList<ChanSourceData> csdList, String name, Database db, Page vpage,
        ViewUser vuser, String contextPath) throws WebUtilException, LdvTableException {
    PageItemList ret = new PageItemList();
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time (UTC)"));
    plot.setGap(10.0);/*from  w w w.  j a v  a  2 s  . c o  m*/

    String baseName = "";
    StringBuilder errors = new StringBuilder();
    int plotNum = 0;
    Color[] colors = { Color.RED, Color.BLUE, Color.MAGENTA, Color.ORANGE, Color.DARK_GRAY, Color.GREEN };
    boolean gotData = false;
    TimeInterval timeRange = null;
    for (ChanSourceData csd : csdList) {
        TimeInterval ti = csd.getTimeRange();
        if (ti != null) {
            if (timeRange == null) {
                timeRange = ti;
            } else if (timeRange.overlaps(ti)) {
                timeRange = timeRange.mergeIntervals(ti);
            } else if (ti.getStartGps() < timeRange.getStartGps()) {
                timeRange.setStartGps(ti.getStartGps());
            } else if (ti.getStopGps() > timeRange.getStopGps()) {
                timeRange.setStopGps(ti.getStopGps());
            }
        }
    }
    if (timeRange != null) {
        for (ChanSourceData csd : csdList) {
            baseName = csd.getChanInfo().getBaseName();
            TimeSeriesCollection mtds = new TimeSeriesCollection();
            String server = csd.getChanInfo().getServer().replace(".caltech.edu", "");
            String legend = String.format("Type: %1$s at %2$s", csd.getChanInfo().getcType(), server);
            TimeSeries ts;
            double[][] data = csd.getGraphData();
            if (data == null) {
                data = new double[2][2];
                data[0][0] = timeRange.getStartGps();
                data[1][0] = timeRange.getStopGps();
                data[0][1] = data[1][1] = 0;
                errors.append("Error getting data for: ").append(legend).append("<br>");
            } else {
                gotData = true;
            }
            for (double[] d : data) {
                d[1] = d[1] <= 1 ? 1 : d[1];
            }
            ts = getTimeSeries(data, legend);

            mtds.addSeries(ts);
            XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA);

            BasicStroke str = new BasicStroke(2);
            int colorIdx = plotNum % colors.length;
            Color color = colors[colorIdx];
            NumberAxis yAxis = new NumberAxis("% Avail");
            yAxis.setRange(0, 100);
            renderer.setBaseFillPaint(color);
            renderer.setSeriesFillPaint(0, Color.WHITE);
            renderer.setBaseStroke(str);
            renderer.setUseFillPaint(true);
            XYPlot subplot = new XYPlot(mtds, null, yAxis, renderer);
            plot.add(subplot);

            plotNum++;
        }

        ChartPanel cpnl;
        JFreeChart chart;
        String gtitle = String.format("Available data for %1$s ", baseName);
        String subTitleTxt = String.format("From %1$s to %2$s",
                TimeAndDate.gpsAsUtcString(timeRange.getStartGps()),
                TimeAndDate.gpsAsUtcString(timeRange.getStopGps()));

        plot.setOrientation(PlotOrientation.VERTICAL);

        chart = new JFreeChart(gtitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

        chart.addSubtitle(new TextTitle(subTitleTxt));
        cpnl = new ChartPanel(chart, false, false, false, false, false);

        PluginSupport psupport = new PluginSupport();
        psupport.setup(db, vpage, vuser);
        int imgId;
        PageItemImage img = null;
        try {
            psupport.setSize(800, 600);
            imgId = psupport.saveImageAsPNG(cpnl);
            String url = String.format("%1$s/view?act=getImg&amp;imgId=%2$d", contextPath, imgId);

            img = new PageItemImage(url, "availability", baseName);

        } catch (SQLException | IOException | NoSuchAlgorithmException ex) {
            String ermsg = String.format("Error creating or saving image: %1$s - $2$s",
                    ex.getClass().getSimpleName(), ex.getLocalizedMessage());
            errors.append(ermsg);

        }
        if (errors.length() > 0) {
            ret.add(errors.toString());
        }
        if (img != null) {
            ret.add(img);
        }
    } else {
        ret.add("No data to plot.");
    }
    return ret;
}