Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setSeriesStroke

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setSeriesStroke

Introduction

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

Prototype

public void setSeriesStroke(int series, Stroke stroke) 

Source Link

Document

Sets the stroke used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java

/**
 * Creates a chart.//from w w w . ja  v a 2 s .co  m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    //http://www.java2s.com/Code/Java/Chart/JFreeChartDualAxisDemo2.htm
    String xlabel = "Delay (ps)";
    String ylabel = "Signal (DN)";

    // create the chart with findmaxpoint results
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            xlabel, // x axis label
            ylabel, // y axis label
            findMaxpointData_, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot plot = chart.getXYPlot();
    // deal with axes and add second dataset
    final NumberAxis yaxis1 = (NumberAxis) plot.getRangeAxis();
    yaxis1.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    yaxis1.setLabelFont(new Font("Dialog", Font.PLAIN, 10));
    final NumberAxis yaxis2 = new NumberAxis(null);
    final NumberAxis xaxis = (NumberAxis) plot.getDomainAxis();
    xaxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    xaxis.setLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.setRangeAxis(1, yaxis2);
    plot.setDataset(1, gatePositionData_);
    plot.mapDatasetToRangeAxis(1, 1);
    yaxis1.setRange(0, 5000);
    yaxis2.setRange(-1, 1);
    yaxis2.setTickLabelsVisible(false);
    xaxis.setRange(0, 16666);

    // deal with visuals

    final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true, true);
    renderer1.setSeriesPaint(0, Color.RED);
    renderer1.setSeriesStroke(0, new BasicStroke(3));

    //        renderer1.setBaseShapesVisible(true);
    //        renderer1.setSeriesShape(0, ShapeUtilities.createDiagonalCross(4,1));

    plot.setRenderer(0, renderer1);

    //        final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
    renderer2.setSeriesPaint(0, Color.CYAN);
    renderer2.setSeriesShapesFilled(0, Boolean.TRUE);
    renderer2.setBaseShapesVisible(true);
    renderer2.setShape(new Rectangle(-2, -100, 4, 200));
    renderer2.setOutlineStroke(new BasicStroke(1));
    renderer2.setOutlinePaint(Color.GRAY);
    renderer2.setUseOutlinePaint(true);
    plot.setRenderer(1, renderer2);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    //                
    return chart;

}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetPlot.java

@Override
protected void update() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (ResultKey key : frame.getSelectedResults()) {
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        for (Accumulator accumulator : controller.get(key)) {
            if (!accumulator.keySet().contains(metric)) {
                continue;
            }/* w w  w .  ja  v a2s. c  o m*/

            List<?> list = (List<?>) accumulator.get(metric, accumulator.size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(key, false, true);

            for (Solution solution : population) {
                if (solution.getNumberOfObjectives() == 1) {
                    series.add(solution.getObjective(0), solution.getObjective(0));
                } else if (solution.getNumberOfObjectives() > 1) {
                    series.add(solution.getObjective(0), solution.getObjective(1));
                }
            }

            dataset.addSeries(series);
        }
    }

    JFreeChart chart = ChartFactory.createScatterPlot(metric, localization.getString("text.objective", 1),
            localization.getString("text.objective", 2), dataset, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

        renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
        renderer.setSeriesPaint(i, paint);
        renderer.setSeriesFillPaint(i, paint);
    }

    plot.setRenderer(renderer);

    //add overlay
    if (controller.getShowLastTrace() && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        XYSeriesCollection dataset2 = new XYSeriesCollection();
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        if (controller.getLastAccumulator().keySet().contains(metric)) {
            List<?> list = (List<?>) controller.getLastAccumulator().get(metric,
                    controller.getLastAccumulator().size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(localization.getString("text.last"), false, true);

            for (Solution solution : population) {
                series.add(solution.getObjective(0), solution.getObjective(1));
            }

            dataset2.addSeries(series);
        }

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

From source file:net.nosleep.superanalyzer.analysis.views.LikesView.java

private void createChart() {
    _chart = ChartFactory.createScatterPlot(Misc.getString("LIKES_VS_PLAYS"),
            Misc.getString("ALBUM_PLAY_COUNT"), Misc.getString("ALBUM_RATING"), _dataset,
            PlotOrientation.VERTICAL, false, true, false);

    _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("LIKES_VS_PLAYS_SUBTITLE")));

    XYPlot plot = (XYPlot) _chart.getPlot();

    ChartUtilities.applyCurrentTheme(_chart);

    plot.setDomainPannable(true);//from w w w .ja  v a2  s  .  c  o m
    plot.setRangePannable(true);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    // get rid of the little line above/next to the axis
    plot.setDomainZeroBaselinePaint(Color.white);
    plot.setRangeZeroBaselinePaint(Color.white);

    /*
     * NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
     * domainAxis.setAutoRangeIncludesZero(false);
     * 
     * domainAxis.setTickMarkInsideLength(2.0f);
     * domainAxis.setTickMarkOutsideLength(2.0f);
     * 
     * domainAxis.setMinorTickCount(2);
     * domainAxis.setMinorTickMarksVisible(true);
     */
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    /*
     * rangeAxis.setTickMarkInsideLength(2.0f);
     * rangeAxis.setTickMarkOutsideLength(2.0f);
     * rangeAxis.setMinorTickCount(2);
     * rangeAxis.setMinorTickMarksVisible(true);
     */
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // format the line renderer after applying the theme
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    Misc.formatChart(plot);
    renderer.setSeriesPaint(0, Theme.getColorSet()[1]);

}

From source file:jmbench.plots.OperationsVersusSizePlot.java

private void _addErrors(double x[], double y[], int max, String name, int seriesIndex) {
    XYSeries series = createXY(x, y, max, name);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setBaseShapesVisible(false);
    renderer.setDrawSeriesLineAsPath(true);
    renderer.setSeriesPaint(0, getColor(seriesIndex));
    renderer.setSeriesStroke(0, getStroke(seriesIndex, STROKE_SIZE, STROKE_SIZE * 2));

    plot.setRenderer(numDataSets, renderer);
    plot.setDataset(numDataSets, new XYSeriesCollection(series));

    numDataSets++;/*from w  w  w  .j a v a2  s  .c  om*/

    dataNames.add(name);
}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java

public static XYDataset createLineDataset(DataItems dataitems1, DataItems dataitems2,
        Map<String, ArrayList<LinePos>> mapAB, XYPlot xyplot) {
    // ????/*w  w  w .  j  av a 2s  . c om*/
    int modelcount = mapAB.keySet().size();
    long off1 = dataitems1.getElementAt(0).getTime().getTime();
    long off2 = dataitems2.getElementAt(0).getTime().getTime();
    long unit = 0;
    if (dataitems1.getLength() > 0) {
        unit = dataitems1.getElementAt(1).getTime().getTime() - off1;
    } else {
        unit = 3600000;
    }

    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    // ??

    int colorindex = 0;
    int renderercount = 2;
    for (Object se : mapAB.keySet()) {
        ArrayList<LinePos> s = mapAB.get(se);
        int oneModelCount = s.size();

        ArrayList<DataItems> dslist = new ArrayList<DataItems>();
        Iterator it = s.iterator();

        System.out.println("**************");
        System.out.println("?=" + se + ":=" + oneModelCount);

        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
        // ???
        xylineandshaperenderer.setBaseShapesVisible(false);
        // ??
        xylineandshaperenderer.setSeriesLinesVisible(0, true);
        // xylineandshaperenderer.setSeriesShape(0, double1); //?
        // 
        xylineandshaperenderer.setSeriesPaint(0, getcolor(colorindex % 9));
        xylineandshaperenderer.setSeriesFillPaint(0, getcolor(colorindex % 9));
        xylineandshaperenderer.setSeriesOutlinePaint(0, getcolor(colorindex % 9));
        colorindex++;
        xylineandshaperenderer.setUseFillPaint(true);
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());

        xylineandshaperenderer.setBaseShapesVisible(false);
        xylineandshaperenderer.setSeriesStroke(0,
                new BasicStroke(1.0F, 1, 1, 1.0F, new float[] { 15F, 12F }, 0.0F)); // 
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
        xylineandshaperenderer.setBaseItemLabelsVisible(false);

        while (it.hasNext()) {
            LinePos temp = (LinePos) it.next();

            DataItem d1 = new DataItem();
            d1 = dataitems1.getElementAt(temp.A_start);
            DataItem d2 = new DataItem();
            d2 = dataitems2.getElementAt(temp.B_start);
            DataItems ds1 = new DataItems();
            ds1.add1Data(d1);
            ds1.add1Data(d2);
            // dslist.add(ds1);
            XYDataset xydataset1 = createmodeDataset(ds1, off1, se.toString() + ":" + 1, unit);

            DataItem d3 = new DataItem();
            d3 = dataitems1.getElementAt(temp.A_end);
            DataItem d4 = new DataItem();
            d4 = dataitems2.getElementAt(temp.B_end);
            DataItems ds2 = new DataItems();
            ds2.add1Data(d3);
            ds2.add1Data(d4);
            // dslist.add(ds2);
            XYDataset xydataset2 = createmodeDataset(ds2, off1, se.toString() + ":" + 2, unit);

            int datasetCount = xyplot.getDatasetCount();
            XYTextAnnotation localXYTextAnnotation = null;
            int modelx = (temp.A_start + temp.B_end) / 2;
            double modely = (Double.parseDouble(dataitems2.getElementAt(temp.A_start).getData())
                    + Double.parseDouble(dataitems1.getElementAt(temp.B_end).getData())) / 2;
            /*System.out.println("se=" + se + "::" + "x=" + modelx + "y="
                  + modely);*/
            localXYTextAnnotation = new XYTextAnnotation("" + se + ":" + oneModelCount, modelx, modely);
            xyplot.addAnnotation(localXYTextAnnotation);
            /*System.out.println("datasetCount=" + datasetCount);*/

            xyplot.setDataset(datasetCount, xydataset1);
            xyplot.setRenderer(datasetCount, xylineandshaperenderer);
            xyplot.setDataset(datasetCount + 1, xydataset2);
            xyplot.setRenderer(datasetCount + 1, xylineandshaperenderer);

        }

    }
    return xyseriescollection;
}

From source file:org.projectforge.plugins.liquidityplanning.LiquidityChartBuilder.java

/**
 * @param forecast/*from   w  w w. j a v  a 2s  . com*/
 * @param settings (next days)
 * @return
 */
public JFreeChart createXYPlot(final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
    Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);

    final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays());

    final TimeSeries accumulatedSeries = new TimeSeries(
            I18n.getString("plugins.liquidityplanning.forecast.dueDate"));
    final TimeSeries accumulatedSeriesExpected = new TimeSeries(
            ThreadLocalUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected"));
    final TimeSeries worstCaseSeries = new TimeSeries(
            I18n.getString("plugins.liquidityplanning.forecast.worstCase"));
    double accumulatedExpected = settings.getStartAmount().doubleValue();
    double accumulated = accumulatedExpected;
    double worstCase = accumulated;

    final DayHolder dh = new DayHolder();
    final Date lower = dh.getDate();
    for (int i = 0; i < settings.getNextDays(); i++) {
        if (log.isDebugEnabled() == true) {
            log.debug("day: " + i + ", credits=" + cashFlow.getCredits()[i] + ", debits="
                    + cashFlow.getDebits()[i]);
        }
        final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
        if (i > 0) {
            accumulated += cashFlow.getDebits()[i - 1].doubleValue()
                    + cashFlow.getCredits()[i - 1].doubleValue();
            accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue()
                    + cashFlow.getCreditsExpected()[i - 1].doubleValue();
            worstCase += cashFlow.getCredits()[i - 1].doubleValue();
        }
        accumulatedSeries.add(day, accumulated);
        accumulatedSeriesExpected.add(day, accumulatedExpected);
        worstCaseSeries.add(day, worstCase);
        dh.add(Calendar.DATE, 1);
    }
    dh.add(Calendar.DATE, -1);
    final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true);

    int counter = 0;

    final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
    xyDataSeries.addSeries(accumulatedSeries);
    xyDataSeries.addSeries(worstCaseSeries);
    final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.BLACK);
    lineRenderer.setSeriesVisibleInLegend(0, true);
    lineRenderer.setSeriesPaint(1, cb.getGrayMarker());
    lineRenderer.setSeriesStroke(1, cb.getDashedStroke());
    lineRenderer.setSeriesVisibleInLegend(1, true);
    cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries);

    final TimeSeriesCollection accumulatedSet = new TimeSeriesCollection();
    accumulatedSet.addSeries(accumulatedSeriesExpected);
    final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getGreenFill(), cb.getRedFill(),
            true);
    diffRenderer.setSeriesPaint(0, cb.getRedMarker());
    cb.setRenderer(counter, diffRenderer).setDataset(counter++, accumulatedSet).setStrongStyle(diffRenderer,
            false, accumulatedSeriesExpected);
    diffRenderer.setSeriesVisibleInLegend(0, true);

    cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
    return cb.getChart();
}

From source file:de.tsystems.mms.apm.performancesignature.PerfSigBuildActionResultsDisplay.java

private JFreeChart createXYLineChart(final StaplerRequest req, final XYDataset dataset)
        throws UnsupportedEncodingException {
    final String chartDashlet = req
            .getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamChartDashlet());
    final String measure = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamMeasure());
    final String unit = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamUnit());
    String color = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamColor());
    if (StringUtils.isBlank(color))
        color = Messages.PerfSigBuildActionResultsDisplay_DefaultColor();
    else/*from  www . j  a  va2s  .  c om*/
        URLDecoder.decode(req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamColor()), "UTF-8");

    final JFreeChart chart = ChartFactory.createXYLineChart(
            PerfSigUtils.generateTitle(measure, chartDashlet).replaceAll("\\d+\\w", ""), // title
            "%", // category axis label
            unit, // value axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setForegroundAlpha(0.8f);
    xyPlot.setRangeGridlinesVisible(true);
    xyPlot.setRangeGridlinePaint(Color.black);
    xyPlot.setOutlinePaint(null);

    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.decode(color));
    renderer.setSeriesStroke(0, new BasicStroke(2));

    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:tools.descartes.bungee.chart.ChartGenerator.java

private static XYPlot createAllocationPlot(final TimeSeriesCollection dataset) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(false);
    final NumberAxis rangeAxis = new NumberAxis("Resource Amount");
    rangeAxis.setAutoRangeIncludesZero(true);
    //rangeAxis.setTickUnit(new NumberTickUnit(1));
    double lower = Math.min(1, dataset.getRangeBounds(false).getLowerBound()) - 0.2;
    double upper = Math.max(2, dataset.getRangeBounds(false).getUpperBound()) + 0.2;
    rangeAxis.setRange(lower, upper);//from   w  ww.  ja v  a  2  s . c o  m
    final XYPlot allocationPlot = new XYPlot(dataset, null, rangeAxis, renderer);
    allocationPlot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        TimeSeries series = dataset.getSeries(i);
        //addEndSeriesItem(lastDate, series);
        String description = series.getKey().toString();
        renderer.setSeriesStroke(i, new BasicStroke(STROKE_WIDTH));
        if (description.equals(AllocationSeries.CATEGORY.DEMAND.toString())) {
            renderer.setSeriesShapesVisible(i, false);
            renderer.setSeriesPaint(i, Color.RED);
        } else if (description.equals(SupplySeries.TYPE.VM_SCHEDULED.toString())) {
            renderer.setSeriesPaint(i, VARIANT_C_COLOR);
        } else if (description.equals(SupplySeries.TYPE.VM_COMPLETED.toString())) {
            renderer.setSeriesPaint(i, VARIANT_B_COLOR);
        } else if (description.equals(SupplySeries.TYPE.LB_RULE_ADAPTION.toString())) {
            if (dataset.getSeriesCount() != 2) {
                renderer.setSeriesPaint(i, VARIANT_A_COLOR);
            } else {
                renderer.setSeriesPaint(i, Color.BLUE);
            }
        } else if (description.equals(SupplySeries.TYPE.MONITORED.toString())) {
            if (dataset.getSeriesCount() != 2) {
                renderer.setSeriesPaint(i, VARIANT_D_COLOR);
            } else {
                renderer.setSeriesPaint(i, Color.BLUE);
            }
        } else {
            renderer.setSeriesPaint(i, colorForConfig(description));
        }
    }

    return allocationPlot;
}

From source file:mil.tatrc.physiology.biogears.verification.ScenarioPlotTool.java

public void createGraph(String toDir, Paint color, String title, String XAxisLabel, String YAxisLabel,
        XYSeries... xyData) {/*from  w ww  .j a va2 s . c  o  m*/
    new File(toDir).mkdir();

    Log.info("Creating Graph " + toDir + title);
    double resMin0 = 1.e6;
    double resMax0 = -1.e6;
    double resMin1 = 1.e6;
    double resMax1 = -1.e6;

    XYSeriesCollection dataSet = new XYSeriesCollection();
    for (XYSeries data : xyData)
        dataSet.addSeries(data);

    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();

    if (title.contains("Residual")) {
        // Make plot symmetric about x axis
        resMax0 = xyData[0].getMaxY();
        resMin0 = xyData[0].getMinY();
        if (Math.abs(xyData[0].getMinY()) > Math.abs(xyData[0].getMaxY()))
            resMax0 = Math.abs(resMin0);
        if (Math.abs(xyData[0].getMaxY()) > Math.abs(xyData[0].getMinY()))
            resMin0 = -1.0 * Math.abs(resMax0);
        if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
            resMin0 = -0.00001;
            resMax0 = 0.00001;
        }
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly
    } else if (title.contains("Error")) {
        // Make plot symmetric about x axis
        resMax0 = xyData[0].getMaxY();
        resMin0 = xyData[0].getMinY();
        if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
            resMin0 = -0.00001;
            resMax0 = 0.00001;
        }
        if (resMin0 >= 0.0)
            resMin0 = -0.01;
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly

        /*
         yAxis.setTickLabelPaint(new Color(1,0,0));
         yAxis.setTickMarkPaint(new Color(1,0,0));
         yAxis.setAxisLinePaint(new Color(1,0,0));
         yAxis.setLabelPaint(new Color(1,0,0));
                
         ValueAxis xAxis = plot.getDomainAxis();
         xAxis.setTickLabelPaint(new Color(1,0,0));
         xAxis.setTickMarkPaint(new Color(1,0,0));
         yAxis.setAxisLinePaint(new Color(1,0,0));
         yAxis.setLabelPaint(new Color(1,0,0));
         */
    } else {
        if (xyData.length > 1) {
            // Make plot symmetric about x axis
            resMax0 = xyData[0].getMaxY();
            resMin0 = xyData[0].getMinY();
            resMax1 = xyData[1].getMaxY();
            resMin1 = xyData[1].getMinY();
            if (resMin1 < resMin0)
                resMin0 = resMin1;
            if (resMax1 > resMax0)
                resMax0 = resMax1;
            if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
                resMin0 = -0.00001;
                resMax0 = 0.00001;
            }
            if (resMin0 >= 0.0)
                resMin0 = -0.01;
            if (YAxisLabel.indexOf("PlasmaConcentration") > -1)
                plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")"));
            else {
                ValueAxis yAxis = plot.getRangeAxis();
                yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly
            }
        } else {
            // Make plot symmetric about x axis
            resMax0 = xyData[0].getMaxY();
            resMin0 = xyData[0].getMinY();
            if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
                resMin0 = -0.00001;
                resMax0 = 0.00001;
            }
            if (resMin0 >= 0.0)
                resMin0 = -0.01;
            if (YAxisLabel.indexOf("PlasmaConcentration") > -1)
                plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")"));
            else {
                ValueAxis yAxis = plot.getRangeAxis();
                yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly
            }
        }
    }

    formatXYPlot(chart, color);
    //Changing line widths and colors
    XYItemRenderer r = plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(lineWidth);
    r.setSeriesStroke(0, wideLine);
    r.setSeriesStroke(1, wideLine);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    if (xyData.length > 1) {
        renderer.setSeriesStroke(//makes a dashed line
                0, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K)
                new BasicStroke(lineWidth, 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(0, expectedLineColor);
    renderer.setSeriesFillPaint(1, computedLineColor);
    renderer.setSeriesPaint(0, expectedLineColor);
    renderer.setSeriesPaint(1, computedLineColor);

    try {
        if (toDir == null || toDir.isEmpty())
            toDir = ".";
        File JPGFile = new File(toDir + "/" + StringUtils.removeParens(title) + ".jpg");
        ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }
}

From source file:com.alcatel_lucent.nz.wnmsreport.chart.TimeSeriesIuRChartCustomiser.java

public void customise(JFreeChart chart, JRChart jasperchart) {
    XYPlot xyplot = chart.getXYPlot();// ww w  .  ja v  a  2 s  .  c om
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    XYDataset xyDataset = xyplot.getDataset();
    LegendItemCollection legend = xyplot.getLegendItems();
    LegendItemCollection revised = new LegendItemCollection();

    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            if (i < 1) {
                //make line 1 dashed
                renderer.setSeriesStroke(i, stroke_dashed);
            } else {
                //make other lines filled and add to new legend
                renderer.setSeriesStroke(i, stroke_normal);
                revised.add(legend.get(i));
            }
            renderer.setSeriesLinesVisible(i, true);
        }
    }
    xyplot.setFixedLegendItems(revised);
}