Example usage for org.jfree.chart.plot XYPlot setDomainGridlinesVisible

List of usage examples for org.jfree.chart.plot XYPlot setDomainGridlinesVisible

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDomainGridlinesVisible.

Prototype

public void setDomainGridlinesVisible(boolean visible) 

Source Link

Document

Sets the flag that controls whether or not the domain grid-lines are visible.

Usage

From source file:edu.umn.ecology.populus.plot.BasicPlotInfo.java

public ChartTheme getJFreeChartTheme() {
    class PopChartTheme implements ChartTheme {
        private BasicPlotInfo bpiRef;

        public PopChartTheme(BasicPlotInfo bpi) {
            this.bpiRef = bpi;
        }//from w  w  w  .  ja  va 2s  .  c  o m

        public void apply(JFreeChart chart) {
            JFCXYAdapter jfca = new JFCXYAdapter();
            XYPlot plot = chart.getXYPlot();
            plot.setDataset(jfca);

            if (isLogPlot) {
                plot.setRangeAxis(new LogarithmicAxis(""));
            }
            if (isFrequencies) {
                ValueAxis va = plot.getRangeAxis();
                if (va instanceof NumberAxis) {
                    NumberAxis na = (NumberAxis) va;
                    na.setTickUnit(new NumberTickUnit(0.1));
                } else {
                    Logging.log("Range Axis is not NumberAxis, why?", Logging.kWarn);
                }
            }

            if (xMinSet)
                plot.getDomainAxis().setLowerBound(xAxisMin);
            if (xMaxSet)
                plot.getDomainAxis().setUpperBound(xAxisMax);
            if (yMinSet)
                plot.getRangeAxis().setLowerBound(yAxisMin);
            if (yMaxSet)
                plot.getRangeAxis().setUpperBound(yAxisMax);

            //TODO - just use this renderer
            plot.setRenderer(new ChartRendererWithOrientatedShapes(bpiRef));

            XYItemRenderer r = plot.getRenderer();
            //         AbstractXYItemRenderer r = plot.getRenderer();
            if (r instanceof XYLineAndShapeRenderer) {
                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
                for (int i = 0; i < getNumSeries(); i++) {
                    //Set Line
                    renderer.setSeriesPaint(i, getLineColor(i));
                    renderer.setSeriesStroke(i, getLineStroke(i));

                    //Set Symbol
                    renderer.setSeriesFillPaint(i, getSymbolColor(i));
                    renderer.setSeriesOutlinePaint(i, getSymbolColor(i));

                    Shape shape = getSymbolShape(i);
                    if (shape != null) {
                        renderer.setSeriesShape(i, shape);
                        renderer.setSeriesShapesFilled(i, isSymbolOpaque(i));
                        renderer.setUseFillPaint(true);
                        renderer.setUseOutlinePaint(true);
                        renderer.setSeriesShapesVisible(i, true);
                    }
                }
            } else if (r instanceof XYBarRenderer) {
                XYBarRenderer barRenderer = (XYBarRenderer) r;
                barRenderer.setBarPainter(new StandardXYBarPainter());
            } else {
                Logging.log("Unknown renderer type: " + r.getClass(), Logging.kWarn);
            }

            //inner labels, used in AIDS: Therapy
            plot.clearAnnotations();
            Enumeration<InnerLabel> e = innerLabels.elements();
            while (e.hasMoreElements()) {
                InnerLabel lab = (InnerLabel) e.nextElement();
                Logging.log("Adding " + lab.caption + " at " + lab.x + ", " + lab.y);

                XYTextAnnotation annotation = new XYTextAnnotation(lab.caption, lab.x, lab.y);
                annotation.setTextAnchor(TextAnchor.BOTTOM_CENTER);
                annotation.setOutlineVisible(true);
                plot.addAnnotation(annotation);

                //I actually think the annotation above is ugly.  We can use one of these instead in the future, maybe...
                /*PointerAnnotation may look cool...
                 * That 2.0 is the angle, randomly picked
                 * XYPointerAnnotation annotation = new XYPointerAnnotation(lab.caption, lab.x, lab.y, 2.0); 
                 */

                /*
                ValueMarker marker = new ValueMarker(lab.x);
                marker.setLabel(lab.caption);
                marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
                plot.addDomainMarker(marker);
                 */

            }

            //This is set for GD: AMCM
            if (startGridded) {
                plot.setDomainGridlinesVisible(true);
                plot.setDomainGridlinePaint(Color.BLACK);
                plot.setRangeGridlinesVisible(true);
                plot.setRangeGridlinePaint(Color.BLACK);
            }

        }
    }
    return new PopChartTheme(this);
}

From source file:mil.tatrc.physiology.utilities.csv.plots.ActionEventPlotter.java

public void createGraph(PlotJob job, List<List<Double>> timeData, List<List<Double>> data,
        List<LogEvent> events, List<SEAction> actions) {
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet = new XYSeriesCollection();
    double maxY = 0;
    double minY = Double.MAX_VALUE;
    for (int i = 0; i < timeData.size(); i++) {
        if (timeData.get(i) == null || data.get(i) == null) {
            job.bgColor = Color.white; //This hits when we have Expected data but NOT computed data
            continue;
        }/*from  www . jav  a  2 s .  c  o m*/

        title = title + job.headers.get(i) + "_";
        XYSeries dataSeries;
        if (job.isComparePlot) {
            if (timeData.size() > 1)
                dataSeries = plotTool.createXYSeries(i == 0 ? "Expected" : "Computed", timeData.get(i),
                        data.get(i));
            else //If we're comparing but only have one data list, expected is missing, so rename to computed
            {
                dataSeries = plotTool.createXYSeries("Computed", timeData.get(i), data.get(i));
            }
        } else
            dataSeries = plotTool.createXYSeries(job.headers.get(i), timeData.get(i), data.get(i));
        dataSet.addSeries(dataSeries);
        maxY = maxY < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY;
        minY = minY > dataSeries.getMinY() ? dataSeries.getMinY() : minY;
    }
    title = title + "vs_Time_Action_Event_Plot";

    //Override the constructed title if desired (usually for compare plots)
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    double rangeLength = maxY - minY;
    if (Math.abs(rangeLength) < 1e-6) {
        rangeLength = .01;
    }

    class AEEntry implements Comparable<AEEntry> {
        public String name;
        public List<Double> times = new ArrayList<Double>();
        public List<Double> YVals = new ArrayList<Double>();
        public String type = "";

        public int compareTo(AEEntry entry) {
            return times.get(0) < entry.times.get(0) ? -1 : times.get(0) > entry.times.get(0) ? 1 : 0;
        }
    }

    List<AEEntry> allActionsAndEvents = new ArrayList<AEEntry>();

    if (!job.skipAllEvents) {
        //Make points for each event
        //Treat each event like two points on the same vertical line
        for (LogEvent event : events) {
            boolean skip = false;

            for (String eventToSkip : job.eventOmissions) {
                if (event.text.contains(eventToSkip))
                    skip = true;
            }
            if (skip)
                continue;
            AEEntry entry = new AEEntry();

            entry.times.add(event.time.getValue());
            if (job.logAxis)
                entry.YVals.add(maxY);
            else if (job.forceZeroYAxisBound && maxY < 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(maxY + 0.15 * rangeLength);

            entry.times.add(event.time.getValue());
            if (job.logAxis)
                entry.YVals.add(minY);
            else if (job.forceZeroYAxisBound && minY > 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(minY - 0.15 * rangeLength);

            entry.name = event.text + "\r\nt=" + event.time.getValue();
            entry.type = "EVENT:";

            allActionsAndEvents.add(entry);
        }
    }

    if (!job.skipAllActions) {
        //Make similar entries for actions
        for (SEAction action : actions) {
            boolean skip = false;

            for (String actionToSkip : job.actionOmissions) {
                if (action.toString().contains(actionToSkip))
                    skip = true;
            }
            if (skip)
                continue;

            if (action.toString().contains("Advance Time"))
                continue;

            AEEntry entry = new AEEntry();

            entry.times.add(action.getScenarioTime().getValue());
            if (job.logAxis)
                entry.YVals.add(maxY);
            else if (job.forceZeroYAxisBound && maxY < 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(maxY + 0.15 * rangeLength);

            entry.times.add(action.getScenarioTime().getValue());
            if (job.logAxis)
                entry.YVals.add(minY);
            else if (job.forceZeroYAxisBound && minY > 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(minY - 0.15 * rangeLength);

            entry.name = action.toString() + "\r\nt=" + action.getScenarioTime().getValue();
            entry.type = "ACTION:";

            allActionsAndEvents.add(entry);
        }
    }

    //Sort the list
    Collections.sort(allActionsAndEvents);

    //Add a series for each entry
    for (AEEntry entry : allActionsAndEvents) {
        dataSet.addSeries(plotTool.createXYSeries(entry.type + entry.name, entry.times, entry.YVals));
    }

    //If we have experimental data, try to load it and create a dataset for it
    XYSeriesCollection expDataSet = new XYSeriesCollection();
    if (job.experimentalData != null && !job.experimentalData.isEmpty()) {
        Map<String, List<Double>> expData = new HashMap<String, List<Double>>();
        List<String> expHeaders = new ArrayList<String>();

        try {
            CSVContents csv = new CSVContents(job.experimentalData);
            csv.abbreviateContents = 0;
            csv.readAll(expData);
            expHeaders = csv.getHeaders();
        } catch (Exception e) {
            Log.error("Unable to read experimental data");
        }

        if (!expData.isEmpty() && !expHeaders.isEmpty()) {
            List<Double> expTimeData = new ArrayList<Double>();
            expTimeData = expData.get("Time(s)");

            for (String h : expHeaders) //Will assume all headers from exp file will be on same Y axis vs time
            {
                if (h.equalsIgnoreCase("Time(s)"))
                    continue;

                expDataSet.addSeries(plotTool.createXYSeries("Experimental " + h, expTimeData, expData.get(h)));
            }
        }
    }

    //set labels
    String XAxisLabel = "Time(s)";
    String YAxisLabel = job.headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y range
        double resMax0 = maxY;
        double resMin0 = minY;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis().setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.000001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.000001;
        if (job.forceZeroYAxisBound && resMin0 >= 0)
            resMin0 = -.000001;
        if (job.forceZeroYAxisBound && resMax0 <= 0)
            resMax0 = .000001;
        rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis();
        if (rangeLength != 0)
            yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly           

        //Add another Y axis to the right side for easier reading
        ValueAxis rightYAxis = new NumberAxis();
        rightYAxis.setRange(yAxis.getRange());
        rightYAxis.setLabel("");

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null) {
                yAxis.setLowerBound(job.Y1LowerBound);
                rightYAxis.setLowerBound(job.Y1LowerBound);
            }
            if (job.Y1UpperBound != null) {
                yAxis.setUpperBound(job.Y1UpperBound);
                rightYAxis.setUpperBound(job.Y1UpperBound);
            }
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }
        plot.setRangeAxis(0, yAxis);
        plot.setRangeAxis(1, rightYAxis);

    } else {
        double resMin = minY;
        double resMax = maxY;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        LogarithmicAxis rightYAxis = new LogarithmicAxis("");
        yAxis.setLowerBound(resMin);
        rightYAxis.setLowerBound(resMin);
        yAxis.setUpperBound(resMax);
        rightYAxis.setUpperBound(resMax);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null) {
                yAxis.setLowerBound(job.Y1LowerBound);
                rightYAxis.setLowerBound(job.Y1LowerBound);
            }
            if (job.Y1UpperBound != null) {
                yAxis.setUpperBound(job.Y1UpperBound);
                rightYAxis.setUpperBound(job.Y1UpperBound);
            }
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }
        plot.setRangeAxis(0, yAxis);
        plot.setRangeAxis(1, rightYAxis);
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);

    //If we have experimental data, set up the renderer for it and add to plot
    if (expDataSet.getSeriesCount() != 0) {
        XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true); // Shapes only
        renderer1.setSeriesShape(0, ShapeUtilities.createDiamond(8));
        plot.setDataset(1, expDataSet);
        plot.setRenderer(1, renderer1);
        plot.mapDatasetToDomainAxis(1, 0);
        plot.mapDatasetToRangeAxis(1, 0);
    }

    formatAEPlot(job, chart);
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);

    //Changing line widths and colors
    XYItemRenderer r = plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(2.0f);
    Color[] AEcolors = { Color.red, Color.green, Color.black, Color.magenta, Color.orange };
    Color[] dataColors = { Color.blue, Color.cyan, Color.gray, Color.black, Color.red };
    for (int i = 0, cIndex = 0; i < dataSet.getSeriesCount(); i++, cIndex++) {
        r.setSeriesStroke(i, wideLine);
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseShapesVisible(false);
        if (cIndex > 4)
            cIndex = 0;
        if (i < job.headers.size()) //Our actual data
        {
            renderer.setSeriesFillPaint(i, dataColors[cIndex]);
            renderer.setSeriesPaint(i, dataColors[cIndex]);
        } else //actions and events in procession of other colors
        {
            renderer.setSeriesFillPaint(i, AEcolors[cIndex]);
            renderer.setSeriesPaint(i, AEcolors[cIndex]);
        }
    }
    //Special color and format changes for compare plots
    if (job.isComparePlot) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

        for (int i = 0; i < dataSet.getSeriesCount(); i++) {
            if (dataSet.getSeries(i).getKey().toString().equalsIgnoreCase("Expected")) {
                renderer.setSeriesStroke(//makes a dashed line
                        i, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K)
                        new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                                new float[] { 15.0f, 30.0f }, 0.0f));
                renderer.setDrawSeriesLineAsPath(true);
                renderer.setUseFillPaint(true);
                renderer.setBaseShapesVisible(false);
                renderer.setSeriesFillPaint(i, Color.black);
                renderer.setSeriesPaint(i, Color.black);
            }
            if (dataSet.getSeries(i).getKey().toString().equalsIgnoreCase("Computed")) {
                renderer.setSeriesFillPaint(i, Color.red);
                renderer.setSeriesPaint(i, Color.red);
            }
            if (dataSet.getSeries(i).getKey().toString().startsWith("ACTION")) {
                renderer.setSeriesFillPaint(i, Color.green);
                renderer.setSeriesPaint(i, Color.green);
            }
            if (dataSet.getSeries(i).getKey().toString().startsWith("EVENT")) {
                renderer.setSeriesFillPaint(i, Color.blue);
                renderer.setSeriesPaint(i, Color.blue);
            }
        }
    }

    //Split the auto-generated legend into two legends, one for data and one for actions and events
    LegendItemCollection originalLegendCollection = plot.getLegendItems();
    final LegendItemCollection dataLegendCollection = new LegendItemCollection();
    int i;
    for (i = 0; i < job.headers.size() && i < originalLegendCollection.getItemCount(); i++) {
        if (originalLegendCollection.get(i).getLabel().startsWith("ACTION")
                || originalLegendCollection.get(i).getLabel().startsWith("EVENT"))
            break;
        dataLegendCollection.add(originalLegendCollection.get(i));
    }
    final LegendItemCollection remainingLegendCollection = new LegendItemCollection();
    for (; i < originalLegendCollection.getItemCount(); i++) {
        remainingLegendCollection.add(originalLegendCollection.get(i));
    }
    chart.removeLegend();
    LegendItemSource source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(dataLegendCollection);
        }

        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };
    LegendTitle dataLegend = new LegendTitle(source);
    dataLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    dataLegend.setBorder(2, 2, 2, 2);
    dataLegend.setBackgroundPaint(Color.white);
    dataLegend.setPosition(RectangleEdge.TOP);
    dataLegend.setItemFont(new Font("SansSerif", Font.PLAIN, 22));
    chart.addLegend(dataLegend);

    source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(remainingLegendCollection);
        }

        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };
    LegendTitle actionEventsLegend = new LegendTitle(source);
    actionEventsLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    actionEventsLegend.setBorder(2, 2, 2, 2);
    actionEventsLegend.setBackgroundPaint(Color.white);
    actionEventsLegend.setPosition(RectangleEdge.BOTTOM);
    actionEventsLegend.setItemFont(new Font("SansSerif", Font.PLAIN, 22));
    if (!job.hideAELegend && !job.removeAllLegends)
        chart.addLegend(actionEventsLegend);

    if (job.removeAllLegends)
        chart.removeLegend();

    int verticalPixels = 800 + 170 * (allActionsAndEvents.size() / 5);

    //This is a little hacky, but if we want only the legend, just extend Plot() and remove the draw functionality so it makes a blank plot
    class legendPlot extends Plot {
        public void draw(Graphics2D arg0, Rectangle2D arg1, Point2D arg2, PlotState arg3,
                PlotRenderingInfo arg4) {

        }

        public String getPlotType() {
            return null;
        }
    }
    //Then add the legend to that and throw away the original plot
    if (job.legendOnly) {
        chart = new JFreeChart("", null, new legendPlot(), false);
        chart.addLegend(actionEventsLegend);
    }

    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else if (!job.hideAELegend && !job.removeAllLegends)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, verticalPixels);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }
}

From source file:mil.tatrc.physiology.utilities.csv.plots.MultiPlotter.java

@Override
public void plot(LogListener listener, SESubstanceManager subMgr) {
    //fill PlotJob with needed data if it doesn't exist
    PlotJob job = (PlotJob) listener;/* w  w  w .jav  a2 s. c o  m*/
    if (job.dataPath == null || job.dataPath.isEmpty()) {
        job.dataPath = "../verification/Scenarios/" + job.verificationDirectory + "/Current Baseline/";
    }
    if (job.dataFile == null || job.dataFile.isEmpty()) {
        job.dataFile = job.name + "Results.zip";
    }

    //Get data contents for all headers when all data is in one file
    if ((data.isEmpty() || data == null) && job.experimentalData == null) {
        try {
            CSVContents csv = new CSVContents(job.dataPath + job.dataFile);
            csv.abbreviateContents = job.resultsSkipNum;
            for (int i = 0; i < job.headers.size(); i++) {
                List<Double> headerData = new ArrayList<Double>();
                csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData);
                data.put(job.headers.get(i), headerData);
            }
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.dataPath + job.dataFile);
        }
    }
    //Get data contents when we're also using experimental files
    else if ((data.isEmpty() || data == null) && job.experimentalData != null) {
        CSVContents dataCsv = null;
        CSVContents expCsv = null;

        try {
            dataCsv = new CSVContents(job.dataPath + job.dataFile);
            dataCsv.abbreviateContents = job.resultsSkipNum;
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.dataPath + job.dataFile);
        }
        try {
            expCsv = new CSVContents(job.experimentalData);
            expCsv.abbreviateContents = 0; //we'll use all of the experimental data
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.experimentalData);
        }
        try {
            //Get data from X1 and Y1, which should always be from our normal data file
            for (int i = 0; i < job.Y1headers.size(); i++) {
                List<Double> headerData = new ArrayList<Double>();
                dataCsv.readHeader(dataCsv.unitUnderscoreToSpace(job.Y1headers.get(i)), headerData);
                data.put(job.Y1headers.get(i), headerData);
            }
            List<Double> headerData = new ArrayList<Double>();
            dataCsv.readHeader(dataCsv.unitUnderscoreToSpace(job.X1header), headerData);
            data.put(job.X1header, headerData);

            for (int i = 0; i < job.Y2headers.size(); i++) {
                List<Double> headerData2 = new ArrayList<Double>();
                expCsv.readHeader(expCsv.unitUnderscoreToSpace(job.Y2headers.get(i)), headerData2);
                expData.put(job.Y2headers.get(i), headerData2);
            }
            List<Double> headerData2 = new ArrayList<Double>();
            expCsv.readHeader(expCsv.unitUnderscoreToSpace(job.X2header), headerData2);
            expData.put(job.X2header, headerData2);
        } catch (Exception e) {
            Log.error("A problem was encountered reading headers from files.");
        }
    }

    //Catch some errors
    if (job.Y2headers.size() > 0 && job.X2header == null) {
        Log.error("No X2 header specified for job " + job.name
                + ". Each Y axis must have a corresponding X axis.");
        return;
    }

    //Make a dataSeries for desired headers and add to collection(s)
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet1 = new XYSeriesCollection();
    XYSeriesCollection dataSet2 = new XYSeriesCollection();
    double maxY1 = 0;
    double minY1 = Double.MAX_VALUE;
    double maxY2 = 0;
    double minY2 = Double.MAX_VALUE;
    for (int i = 0; i < job.Y1headers.size(); i++) {
        XYSeries dataSeries;
        if (job.experimentalData != null)
            dataSeries = plotTool.createXYSeries("BioGears " + job.Y1headers.get(i), data.get(job.X1header),
                    data.get(job.Y1headers.get(i)));
        else
            dataSeries = plotTool.createXYSeries(job.Y1headers.get(i), data.get(job.X1header),
                    data.get(job.Y1headers.get(i)));
        dataSet1.addSeries(dataSeries);
        title = title + job.Y1headers.get(i) + "_";
        maxY1 = maxY1 < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY1;
        minY1 = minY1 > dataSeries.getMinY() ? dataSeries.getMinY() : minY1;
    }
    for (int i = 0; i < job.Y2headers.size(); i++) {
        XYSeries dataSeries;
        if (job.experimentalData != null)
            dataSeries = plotTool.createXYSeries("Experimental " + job.Y2headers.get(i),
                    expData.get(job.X2header), expData.get(job.Y2headers.get(i)));
        else
            dataSeries = plotTool.createXYSeries(job.Y2headers.get(i), data.get(job.X2header),
                    data.get(job.Y2headers.get(i)));
        dataSet2.addSeries(dataSeries);
        title = title + job.Y2headers.get(i) + "_";
        maxY2 = maxY2 < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY2;
        minY2 = minY2 > dataSeries.getMinY() ? dataSeries.getMinY() : minY2;
    }
    title = title + "vs_" + job.X1header;
    if (job.X2header != null && !job.X1header.equalsIgnoreCase(job.X2header))
        title = title + "_" + job.X2header;

    //Override the constructed title if desired
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    //set labels
    String XAxisLabel = job.X1header;
    String YAxisLabel = job.Y1headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet1, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y1 range
        double resMax0 = maxY1;
        double resMin0 = minY1;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis(0).setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.001;
        double rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis(0);
        if (rangeLength != 0)
            yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly  

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        //Add the second Y axis to the right side
        if (!job.Y2headers.isEmpty()) {
            ValueAxis rightYAxis = new NumberAxis();
            // Determine Y2 range
            double resMax1 = maxY2;
            double resMin1 = minY2;
            if (Double.isNaN(resMax1) || Double.isNaN(resMin1))
                plot.getDomainAxis(1).setLabel("Range is NaN");
            if (DoubleUtils.isZero(resMin1))
                resMin1 = -0.001;
            if (DoubleUtils.isZero(resMax1))
                resMax1 = 0.001;
            rangeLength = resMax1 - resMin1;
            if (rangeLength != 0)
                rightYAxis.setRange(resMin1 - 0.15 * rangeLength, resMax1 + 0.15 * rangeLength);
            rightYAxis.setLabel(job.Y2headers.get(0));

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    } else {
        double resMin = minY1 < minY2 ? minY1 : minY2;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        yAxis.setLowerBound(resMin);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        if (!job.Y2headers.isEmpty()) {
            LogarithmicAxis rightYAxis = new LogarithmicAxis("Log(" + job.Y2headers.get(0) + ")");
            rightYAxis.setLowerBound(resMin);

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
        if (job.X2LowerBound != null)
            plot.getDomainAxis(1).setLowerBound(job.X2LowerBound);
        if (job.X2UpperBound != null)
            plot.getDomainAxis(1).setUpperBound(job.X2UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Add the second dataset if necessary
    if (!job.Y2headers.isEmpty()) {
        plot.setDataset(1, dataSet2);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.X2Label != null && plot.getDomainAxis(1) != null)
        plot.getDomainAxis(1).setLabel(job.X2Label.equalsIgnoreCase("None") ? "" : job.X2Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);
    if (job.Y2Label != null && plot.getRangeAxis(1) != null)
        plot.getRangeAxis(1).setLabel(job.Y2Label.equalsIgnoreCase("None") ? "" : job.Y2Label);

    //Format lines and colors
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);
    formatMultiPlot(job, chart, dataSet1, dataSet2);

    //Handle legends
    if (job.removeAllLegends)
        chart.removeLegend();

    //Make the file
    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }

}

From source file:mil.tatrc.physiology.utilities.csv.plots.ConvexHullPlotter.java

public void plot(LogListener listener, SESubstanceManager subMgr) {
    //fill PlotJob with needed data if it doesn't exist
    PlotJob job = (PlotJob) listener;/*from   w ww .java2  s  .  c o m*/
    if (job.dataPath == null || job.dataPath.isEmpty()) {
        job.dataPath = "../verification/Scenarios/" + job.verificationDirectory + "/Current Baseline/";
    }
    if (job.dataFile == null || job.dataFile.isEmpty()) {
        job.dataFile = job.name + "Results.zip";
    }

    //Get data contents for all headers
    if (data.isEmpty() || data == null) {
        try {
            CSVContents csv = new CSVContents(job.dataPath + job.dataFile);
            csv.abbreviateContents = job.resultsSkipNum;
            for (int i = 0; i < job.headers.size(); i++) {
                List<Double> headerData = new ArrayList<Double>();
                csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData);
                data.put(job.headers.get(i), headerData);
            }
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.dataPath + job.dataFile);
        }
    }

    //Catch some errors
    if (job.Y2headers.size() > 0 && job.X2header == null) {
        Log.error("No X2 header specified for job " + job.name
                + ". Each Y axis must have a corresponding X axis.");
        return;
    }

    //Make a dataSeries for desired headers and add to collection(s)
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet1 = new XYSeriesCollection();
    XYSeriesCollection dataSet2 = new XYSeriesCollection();
    double maxY1 = 0;
    double minY1 = Double.MAX_VALUE;
    double maxY2 = 0;
    double minY2 = Double.MAX_VALUE;
    for (int i = 0; i < job.Y1headers.size(); i++) {
        XYSeries dataSeriesTop;
        XYSeries dataSeriesBottom;
        XYSeries dataSeriesLeft;
        XYSeries dataSeriesRight;

        //For convex hulls, we have to reorder points before inserting into the dataset
        ConvexHullMaker maker = new ConvexHullMaker();
        List<List<Double>> newVals = new ArrayList<List<Double>>();
        List<List<Double>> splitVals = new ArrayList<List<Double>>();
        newVals = maker.make(data.get(job.X1header), data.get(job.Y1headers.get(i)));
        splitVals = splitHull(newVals);
        dataSeriesTop = plotTool.createXYSeries(job.Y1headers.get(i), splitVals.get(0), splitVals.get(1));
        dataSeriesBottom = plotTool.createXYSeries("", splitVals.get(2), splitVals.get(3));
        dataSeriesLeft = plotTool.createXYSeries("", splitVals.get(4), splitVals.get(5));
        dataSeriesRight = plotTool.createXYSeries("", splitVals.get(6), splitVals.get(7));

        dataSeriesBottom.setKey("REMOVE");
        dataSeriesLeft.setKey("REMOVE");
        dataSeriesRight.setKey("REMOVE");

        dataSet1.addSeries(dataSeriesTop);
        dataSet1.addSeries(dataSeriesBottom);
        dataSet1.addSeries(dataSeriesLeft);
        dataSet1.addSeries(dataSeriesRight);

        title = title + job.Y1headers.get(i) + "_";
        maxY1 = maxY1 < dataSeriesTop.getMaxY() ? dataSeriesTop.getMaxY() : maxY1;
        minY1 = minY1 > dataSeriesBottom.getMinY() ? dataSeriesBottom.getMinY() : minY1;
    }
    for (int i = 0; i < job.Y2headers.size(); i++) {
        XYSeries dataSeriesTop;
        XYSeries dataSeriesBottom;
        XYSeries dataSeriesLeft;
        XYSeries dataSeriesRight;

        ConvexHullMaker maker = new ConvexHullMaker();
        List<List<Double>> newVals = new ArrayList<List<Double>>();
        List<List<Double>> splitVals = new ArrayList<List<Double>>();
        newVals = maker.make(data.get(job.X2header), data.get(job.Y2headers.get(i)));
        splitVals = splitHull(newVals);
        dataSeriesTop = plotTool.createXYSeries(job.Y2headers.get(i), splitVals.get(0), splitVals.get(1));
        dataSeriesBottom = plotTool.createXYSeries("", splitVals.get(2), splitVals.get(3));
        dataSeriesLeft = plotTool.createXYSeries("", splitVals.get(4), splitVals.get(5));
        dataSeriesRight = plotTool.createXYSeries("", splitVals.get(6), splitVals.get(7));

        dataSeriesBottom.setKey("REMOVE");
        dataSeriesLeft.setKey("REMOVE");
        dataSeriesRight.setKey("REMOVE");

        dataSet2.addSeries(dataSeriesTop);
        dataSet2.addSeries(dataSeriesBottom);
        dataSet2.addSeries(dataSeriesLeft);
        dataSet2.addSeries(dataSeriesRight);

        title = title + job.Y2headers.get(i) + "_";
        maxY2 = maxY2 < dataSeriesTop.getMaxY() ? dataSeriesTop.getMaxY() : maxY2;
        minY2 = minY2 > dataSeriesBottom.getMinY() ? dataSeriesBottom.getMinY() : minY2;
    }
    title = title + "vs_" + job.X1header;
    if (job.X2header != null && !job.X1header.equalsIgnoreCase(job.X2header))
        title = title + "_" + job.X2header;

    //Override the constructed title if desired
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    //set labels
    String XAxisLabel = job.X1header;
    String YAxisLabel = job.Y1headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet1, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y1 range
        double resMax0 = maxY1;
        double resMin0 = minY1;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis(0).setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.001;
        double rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis(0);
        yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly  

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        //Add the second Y axis to the right side
        if (!job.Y2headers.isEmpty()) {
            ValueAxis rightYAxis = new NumberAxis();
            // Determine Y2 range
            double resMax1 = maxY2;
            double resMin1 = minY2;
            if (Double.isNaN(resMax1) || Double.isNaN(resMin1))
                plot.getDomainAxis(1).setLabel("Range is NaN");
            if (DoubleUtils.isZero(resMin1))
                resMin1 = -0.001;
            if (DoubleUtils.isZero(resMax1))
                resMax1 = 0.001;
            rangeLength = resMax1 - resMin1;
            rightYAxis.setRange(resMin1 - 0.15 * rangeLength, resMax1 + 0.15 * rangeLength);
            rightYAxis.setLabel(job.Y2headers.get(0));

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    } else {
        double resMin = minY1 < minY2 ? minY1 : minY2;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        yAxis.setLowerBound(resMin);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        if (!job.Y2headers.isEmpty()) {
            LogarithmicAxis rightYAxis = new LogarithmicAxis("Log(" + job.Y2headers.get(0) + ")");
            rightYAxis.setLowerBound(resMin);

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
        if (job.X2LowerBound != null)
            plot.getDomainAxis(1).setLowerBound(job.X2LowerBound);
        if (job.X2UpperBound != null)
            plot.getDomainAxis(1).setUpperBound(job.X2UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Add the second dataset if necessary
    if (!job.Y2headers.isEmpty()) {
        plot.setDataset(1, dataSet2);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.X2Label != null && plot.getDomainAxis(1) != null)
        plot.getDomainAxis(1).setLabel(job.X2Label.equalsIgnoreCase("None") ? "" : job.X2Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);
    if (job.Y2Label != null && plot.getRangeAxis(1) != null)
        plot.getRangeAxis(1).setLabel(job.Y2Label.equalsIgnoreCase("None") ? "" : job.Y2Label);

    //Format lines and colors
    plotTool.formatXYPlot(chart, job.bgColor);
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);
    formatConvexHullPlot(job, chart, dataSet1, dataSet2);

    //Handle legends
    if (job.removeAllLegends)
        chart.removeLegend();

    //Make the file
    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }

}

From source file:probe.com.view.core.chart4j.VennDiagramPanel.java

/**
 * Update the plot./*from   w ww  . j  a  v  a 2s  .c o  m*/
 */
public void updatePlot() {

    //        plotPanel.removeAll();
    tooltipToDatasetMap = new HashMap<String, String>();

    DefaultXYZDataset xyzDataset = new DefaultXYZDataset();

    chart = ChartFactory.createBubbleChart(null, "X", "Y", xyzDataset, PlotOrientation.VERTICAL, false, true,
            false);
    XYPlot plot = chart.getXYPlot();

    if (currentVennDiagramType == VennDiagramType.ONE_WAY) {
        plot.getRangeAxis().setRange(0.86, 1.24);
        plot.getDomainAxis().setRange(0.85, 1.25);
    } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) {
        plot.getRangeAxis().setRange(0.86, 1.24);
        plot.getDomainAxis().setRange(0.85, 1.25);
    } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) {
        plot.getRangeAxis().setRange(0.86, 1.24);
        plot.getDomainAxis().setRange(0.85, 1.25);
    } else {
        plot.getRangeAxis().setRange(-0.04, 0.6);
        plot.getDomainAxis().setRange(-0.08, 0.7);
    }

    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);

    double radius = 0.1;
    Ellipse2D ellipse = new Ellipse2D.Double(1 - radius, 1 - radius, radius + radius, radius + radius);
    XYShapeAnnotation xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f),
            new Color(140, 140, 140, 150), datasetAColor); // @TODO: make it possible set the line color and width?
    plot.addAnnotation(xyShapeAnnotation);

    if (currentVennDiagramType == VennDiagramType.TWO_WAY
            || currentVennDiagramType == VennDiagramType.THREE_WAY) {
        ellipse = new Ellipse2D.Double(1 - radius + 0.1, 1 - radius, radius + radius, radius + radius);
        xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150),
                datasetBColor);
        plot.addAnnotation(xyShapeAnnotation);
    }

    if (currentVennDiagramType == VennDiagramType.THREE_WAY) {
        ellipse = new Ellipse2D.Double(1 - radius + 0.05, 1 - radius + 0.1, radius + radius, radius + radius);
        xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150),
                datasetCColor);
        plot.addAnnotation(xyShapeAnnotation);
    }

    XYTextAnnotation anotation;

    if (currentVennDiagramType == VennDiagramType.ONE_WAY) {

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 1.0, 1.0);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(),
                    legendDatasetAThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }

    } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) {

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 1.0);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 1.0);
        anotation.setToolTipText(groupNames.get("b"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "b");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 1.0);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ab");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(),
                    legendDatasetAThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(),
                    legendDatasetBThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }

    } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) {

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 0.97);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 0.97);
        anotation.setToolTipText(groupNames.get("b"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "b");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 0.97);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ab");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 1.05, 1.14);
        anotation.setToolTipText(groupNames.get("c"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "c");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.99, 1.065);
        anotation.setToolTipText(
                "<html>" + groupNames.get("a") + "  &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ac");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 1.11, 1.065);
        anotation
                .setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bc");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 1.05, 1.036);
        anotation.setToolTipText("<html>" + groupNames.get("a") + "  &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abc");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(),
                    legendDatasetAThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(),
                    legendDatasetBThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCThreeWay.getX(),
                    legendDatasetCThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }

    } else if (currentVennDiagramType == VennDiagramType.FOUR_WAY) {

        XYBoxAnnotation anotation2 = new XYBoxAnnotation(0, 0, 0.2, 0.5, new BasicStroke(2), Color.LIGHT_GRAY,
                datasetAColor);
        plot.addAnnotation(anotation2);

        anotation2 = new XYBoxAnnotation(0.1, 0, 0.3, 0.4, new BasicStroke(2), Color.LIGHT_GRAY, datasetBColor);
        plot.addAnnotation(anotation2);

        anotation2 = new XYBoxAnnotation(0, 0.1, 0.4, 0.3, new BasicStroke(2), Color.LIGHT_GRAY, datasetCColor);
        plot.addAnnotation(anotation2);

        anotation2 = new XYBoxAnnotation(0, 0, 0.5, 0.2, new BasicStroke(2), Color.LIGHT_GRAY, datasetDColor);
        plot.addAnnotation(anotation2);

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.15, 0.45);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 0.15, 0.35);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ab");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 0.15, 0.25);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abc");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abcd").size(), 0.15, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("c") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abcd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abd").size(), 0.15, 0.05);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.05, 0.25);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ac");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("acd").size(), 0.05, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("c")
                + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "acd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ad").size(), 0.05, 0.05);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ad");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 0.25, 0.35);
        anotation.setToolTipText("<html>" + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "b");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 0.25, 0.25);
        anotation
                .setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bc");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bcd").size(), 0.25, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("c")
                + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bcd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bd").size(), 0.25, 0.05);
        anotation
                .setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 0.35, 0.25);
        anotation.setToolTipText("<html>" + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "c");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("cd").size(), 0.35, 0.15);
        anotation
                .setToolTipText("<html>" + groupNames.get("c") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "cd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("d").size(), 0.45, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "d");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAFourWay.getX(),
                    legendDatasetAFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBFourWay.getX(),
                    legendDatasetBFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCFourWay.getX(),
                    legendDatasetCFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("d"), legendDatasetDFourWay.getX(),
                    legendDatasetDFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }
    }

    // set up the renderer
    XYBubbleRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    plot.setRenderer(renderer);

    // make all datapoints semitransparent
    plot.setForegroundAlpha(0.5f);

    // remove space before/after the domain axis
    plot.getDomainAxis().setUpperMargin(0);
    plot.getDomainAxis().setLowerMargin(0);

    plot.setRangeGridlinePaint(Color.black);

    // hide unwanted chart details
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    chart.getPlot().setOutlineVisible(false);

    // set background color
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setBackgroundPaint(Color.WHITE);
    chartPanel = new ChartPanel(chart);

    // disable the pop up menu
    chartPanel.setPopupMenu(null);

    chartPanel.setBackground(Color.WHITE);

    // add the plot to the chart
    //        plotPanel.add(chartPanel);
    //        plotPanel.revalidate();
    //        plotPanel.repaint();
    //
    //      this.add(plotPanel);
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.LinePlot.java

/** 
 * Creates the chart.//  w w  w  .  j a v a  2  s.c  om
 * @see ChartObject#createChar()
 */
void createChart() {
    for (int i = 0; i < colours.size(); i++)
        renderer.setSeriesPaint(i, colours.get(i));
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }

    chart = new JFreeChart(title, plot);
}