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

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

Introduction

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

Prototype

public void setBackgroundAlpha(float alpha) 

Source Link

Document

Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.

Usage

From source file:com.windows.Chart.java

public static JFreeChart createChart(XYDataset dataset) {
    //   /*from w  w w  .ja v a  2 s  .  com*/
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLine Chart Demo", //    
            "??", // categoryAxisLabel categoryX      
            "?", // valueAxisLabelvalueY      
            dataset, // dataset      
            PlotOrientation.VERTICAL, true, // legend      
            false, // tooltips      
            false); // URLs   
    // CategoryPlot?????      
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    //  ?      
    plot.setBackgroundAlpha(0.5f);
    return jfreechart;
}

From source file:diplomawork.model.JPEGSaver.java

public void saveChartToFile(JFreeChart chart, boolean trainFlag) {
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.setBackgroundAlpha(0);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setOutlinePaint(null);/*from   w ww  .  j  av  a  2 s  .co m*/
    XYItemRenderer r = plot.getRenderer();

    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesPaint(0, Color.BLACK);
    }
    plot.getRenderer().setSeriesStroke(0, new java.awt.BasicStroke(4f));
    File f = null;
    if (trainFlag) {
        nameOfJPGFile = "src/resorce/TranePlot" + trainCount++ + ".jpg";
        f = new File(nameOfJPGFile);
    } else {
        //            f = new File("src/resorce/Plot" + n++ + ".jpg");
        f = new File("src/resorce/Plot" + ".jpg");
    }

    try {
        ChartUtilities.saveChartAsJPEG(f, chart, 80, 80);
    } catch (IOException ex) {
        Logger.getLogger(JPEGSaver.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.perdian.apps.dashboard.support.chart.ChartCreator.java

public JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(this.getTitle(), null, null, dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(null);//  w  ww .j  ava 2s . c  o m
    chart.setBackgroundImageAlpha(0.0f);
    if (chart.getTitle() != null) {
        chart.getTitle().setFont(new Font(this.getFontName(), Font.BOLD, 14));
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundAlpha(0.0f);
    plot.setOutlinePaint(this.getColor());
    plot.getDomainAxis().setVisible(false);
    plot.getDomainAxis().setAxisLineVisible(false);
    plot.getDomainAxis().setMinorTickCount(10);
    plot.getDomainAxis().setTickMarksVisible(false);
    if (this.getDomainTickUnits() != null) {
        plot.getDomainAxis().setStandardTickUnits(this.getDomainTickUnits());
    }
    plot.getRangeAxis().setVisible(true);
    plot.getRangeAxis().setAxisLineVisible(false);
    plot.getRangeAxis().setTickLabelFont(new Font(this.getFontName(), Font.PLAIN, 10));
    plot.getRangeAxis().setTickLabelPaint(this.getColor());
    plot.getRangeAxis().setTickMarksVisible(false);
    if (this.getRangeTickUnits() != null) {
        plot.getRangeAxis().setStandardTickUnits(this.getRangeTickUnits());
    }
    plot.getRangeAxis().setAttributedLabel(this.getRangeAxisLabel());

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < this.getStrokeDefinitions().size(); i++) {
        ChartStrokeDefinition strokeDefinition = this.getStrokeDefinitions().get(i);
        strokeDefinition.applyTo(renderer, i);
    }

    return chart;

}

From source file:experiments.SimpleExample.java

public JFreeChart createChart() {
    XYSeries xyseries = new XYSeries("Fitness Line");
    xyseries.add(0.0D, 0.0D);/*from ww w . ja va2s.  c  om*/
    for (int i = 1; i <= fitlist.size(); i++) {
        xyseries.add(i, fitlist.get(i - 1));
    }
    XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //?XYSeriesCollectionXYSeries  
    xyseriescollection.addSeries(xyseries);
    //?  
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Line Chart Demo", //      
            "Iteration", // categoryAxisLabel categoryX     
            "FitnessValue", // valueAxisLabelvalueY     
            xyseriescollection, // dataset     
            PlotOrientation.VERTICAL, true, // legend     
            false, // tooltips     
            false); // URLs     

    // CategoryPlot?????     
    XYPlot plot = jfreechart.getXYPlot();
    // ? ?     
    plot.setBackgroundAlpha(0.5f);
    plot.setForegroundAlpha(0.5f);
    //        XYPlot xyplot = jfreechart.getXYPlot();  
    //??  
    ValueAxis xx = plot.getDomainAxis();
    //??  
    xx.setAutoRange(true);
    //        xx.setRange(0.0, 2000);

    ValueAxis yy = plot.getRangeAxis();
    yy.setRange(600.0, 1000);

    return jfreechart;
}

From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartLineGraphicCreator.java

/**
 * Creates the chart and applies some styling.
 * @return the JFreeChart wrapped in an iteratec API symbol.
 *///from  w  w  w  .  j a  v  a2  s.c om
private JFreeChartSymbol createChart() {
    try {
        ChartFactory cf = new ChartFactory();
        cf.setTitle(title);
        cf.setxAxis(xAxis);
        cf.setyAxis(yAxis);
        JFreeChart chart = cf.createXYStepChart(dataset);
        LegendTitle legend = chart.getLegend();
        legend.setPosition(RectangleEdge.RIGHT);
        legend.setVisible(!emptyDataset); // don't show a legend, if the dataset is empty
        XYPlot xyplot = (XYPlot) chart.getPlot();
        xyplot.setBackgroundAlpha(0.4f);
        JFreeChartSymbol jfcs = new JFreeChartSymbol(chart);
        jfcs.setWidth(xResolution);
        jfcs.setHeight(yResolution);
        return jfcs;
    } catch (Exception e) {
        throw new IteraplanBusinessException(e);
    }
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a line chart./* w w  w. j  av  a2s . c om*/
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @param includeZero
 *            True when zero shall be included to the axis range.
 * @return JfreeChart instance.
 */
public JFreeChart createXYLineSplineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        XYDataset dataset, boolean includeZero, boolean drawShapes) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundAlpha(0.4f);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.025);
    domainAxis.setUpperMargin(0.025);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(includeZero);
    plot.setRenderer(new XYSplineRenderer(100));
    XYSplineRenderer renderer = (XYSplineRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseShapesVisible(drawShapes);
    renderer.setBaseShapesFilled(true);
    return chart;
}

From source file:org.sonar.server.charts.deprecated.SparkLinesChart.java

private void configurePlot() {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setDataset(dataset);// w  ww .java 2  s .c  o m
    plot.setDomainAxis(x);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setRangeAxis(y);
    plot.setRenderer(renderer);
    plot.setBackgroundAlpha(0.0f);
}

From source file:org.esa.beam.visat.toolviews.stat.StatisticsPanel.java

private static ChartPanel getScatterPlotPanel(XIntervalSeriesCollection dataset, String xAxisLabel,
        String yAxisLabel, Color color, double domainBounds[], double rangeBounds[]) {
    //  JFreeChart chart = ChartFactory.createScatterPlot(
    JFreeChart chart = ChartFactory.createXYLineChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, // Legend?
            true, // tooltips
            false // url
    );/* ww w. j a va  2  s  .  co  m*/
    final XYPlot xyPlot = chart.getXYPlot();
    //   xyPlot.setForegroundAlpha(0.85f);
    xyPlot.setBackgroundAlpha(0.0f);
    xyPlot.setNoDataMessage("No data");
    xyPlot.setAxisOffset(new RectangleInsets(5, 5, 5, 10));

    // todo Danny set bounds here

    //        if (domainBounds[0] != domainBounds[1]) {
    //            xyPlot.getDomainAxis().setLowerBound(domainBounds[0]);
    //            xyPlot.getDomainAxis().setUpperBound(domainBounds[1]);
    //        }
    //
    //        if (rangeBounds[0] != rangeBounds[1]) {
    //            xyPlot.getRangeAxis().setLowerBound(rangeBounds[0]);
    //            xyPlot.getRangeAxis().setUpperBound(rangeBounds[1]);
    //        }

    if (!Double.isNaN(domainBounds[0])) {
        xyPlot.getDomainAxis().setLowerBound(domainBounds[0]);
    }

    if (!Double.isNaN(domainBounds[1])) {
        xyPlot.getDomainAxis().setUpperBound(domainBounds[1]);
    }

    if (!Double.isNaN(rangeBounds[0])) {
        xyPlot.getRangeAxis().setLowerBound(rangeBounds[0]);
    }

    if (!Double.isNaN(rangeBounds[1])) {
        xyPlot.getRangeAxis().setUpperBound(rangeBounds[1]);
    }

    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    renderer.setSeriesPaint(0, color);
    renderer.setUseFillPaint(true);
    renderer.setDrawOutlines(true);
    renderer.setSeriesShapesFilled(0, true);
    renderer.setSeriesFillPaint(0, color);

    ChartPanel chartPanel = new ChartPanel(chart);
    //    chartPanel.setPreferredSize(new Dimension(300, 200));

    return chartPanel;
}