Example usage for org.jfree.chart JFreeChart getPlot

List of usage examples for org.jfree.chart JFreeChart getPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getPlot.

Prototype

public Plot getPlot() 

Source Link

Document

Returns the plot for the chart.

Usage

From source file:org.ewhoxford.swt.bloodpressure.ui.MeasurePageTab.java

/**
 * Creates a chart./*from w  w  w.j ava2  s.c  o  m*/
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset, XYPlot bpMeasureXYPlot) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Blood Pressure Measure", // title
            "time(s)", // x-axis label
            "Pressure(mmHg)", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    bpMeasureXYPlot = (XYPlot) chart.getPlot();
    bpMeasureXYPlot.setBackgroundPaint(Color.lightGray);
    bpMeasureXYPlot.setDomainGridlinePaint(Color.white);
    bpMeasureXYPlot.setRangeGridlinePaint(Color.white);

    // bpMeasureXYPlot.setAxisOffset(new RectangleInsets(300, 0, 0,
    // BOUNDARY_NUMBER_OF_POINTS));
    // bpMeasureXYPlot.setDomainCrosshairVisible(true);
    // bpMeasureXYPlot.setRangeCrosshairVisible(true);

    XYItemRenderer r = bpMeasureXYPlot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    ValueAxis axis = bpMeasureXYPlot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    // axis.setRange(0, 1000);
    axis.setAutoRange(true);
    axis = bpMeasureXYPlot.getRangeAxis();
    axis.setRange(0, 300.0);

    // DateAxis axis = (DateAxis) plot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    // axis.setRange(0, 1000);

    return chart;

}

From source file:edu.unc.LCCC.caBIG.DWD.javaCode.visualization.SetUpPlotWindow.java

public static JPanel createXYLineAndShapeRendererChart(XYDataset data, String x, String y, int w, int h) {
    //XYDataset data = new SampleXYDataset2();
    JFreeChart chart = ChartFactory.createScatterPlot(null, // the title of the chart
            x, // the label for the X axis
            y, // the label for the Y axis
            data, // the dataset for the chart
            PlotOrientation.VERTICAL, // the orientation of the chart
            true, // a flag specifying whether or not a legend is required
            true, // a flag specifying whether or not tooltips should be generated
            false); // a flag specifying whether or not the chart should generate URLs

    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);

    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);

    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);

    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);//www  .  j  a  va  2s.co m
    plot.setRenderer(renderer);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(w, h));

    return chartPanel;
}

From source file:de.xirp.chart.ChartManager.java

/**
 * Returns a time series chart. The chart is generated from the
 * given {@link de.xirp.db.Record} and key array. The
 * record is evaluated from the given start to the given stop
 * time. The flag <code>origTime</code> is an indicator for the
 * database query. If it is <code>true</code> the start and stop
 * time is overridden and the original time of the record is used.
 * /* w  ww. j  a v  a2 s .  c o m*/
 * @param record
 *            The record containing the data.
 * @param keys
 *            The keys to use.
 * @param start
 *            The start time.
 * @param stop
 *            The stop time.
 * @param origTime
 *            Flag for indicating if the original time should be
 *            used.
 * @return A time series chart.
 * @see org.jfree.chart.JFreeChart
 * @see de.xirp.db.Record
 */
private static JFreeChart createTimeSeriesChart(Record record, String[] keys, long start, long stop,
        boolean origTime) {

    String chartTitle = createChartTitle(record, keys);

    List<Observed> all = new ArrayList<Observed>();
    TimeSeriesCollection dataset = createTimeSeriesAndFillAllObservedList(all, record, keys, origTime, start,
            stop);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, I18n.getString("ChartManager.text.time"), //$NON-NLS-1$
            I18n.getString("ChartManager.text.value"), dataset, true, true, false); //$NON-NLS-1$

    XYPlot plot = (XYPlot) chart.getPlot();
    setXYPlot(plot, new Date(record.getStart()));

    exportAutomatically(all, chart);

    return chart;
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.SeriesOrderCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        CategoryDataset dataset = new SeriesOrderCategoryDataset(chart.getCategoryPlot().getDataset(),
                seriesOrderBy, seriesOrderType);
        chart.getCategoryPlot().setDataset(dataset);
    }//w ww  . j  a va 2 s.com
}

From source file:ca.sqlpower.wabit.swingui.chart.effect.ScatterChartAnimatorFactory.java

public ChartAnimator createAnimator(JFreeChart chart) throws CantAnimateException {
    XYPlot xyplot;/*  ww  w .j  av a 2  s  . c o  m*/
    if (chart.getPlot() instanceof XYPlot) {
        xyplot = (XYPlot) chart.getPlot();
    } else {
        throw new CantAnimateException("This animator needs an XYPlot. You gave " + chart.getPlot());
    }
    return new ScatterChartAnimator(getFrameCount(), getFrameDelay(), xyplot, interpolator);
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.ShowPercentagesCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        if (chart.getCategoryPlot().getDataset() != null) {
            CategoryDataset dataset;/*from   w  ww .  jav  a2  s .  co  m*/
            if (!(chart.getCategoryPlot().getRenderer() instanceof GroupedStackedBarRenderer)) {
                dataset = new PercentageCategoryDataset(chart.getCategoryPlot().getDataset());
            } else {
                dataset = new PercentageGroupedCategoryDataset(chart.getCategoryPlot().getDataset());
            }
            chart.getCategoryPlot().setDataset(dataset);
        }
        if (StringUtils.isBlank(chart.getCategoryPlot().getRangeAxis().getLabel())) {
            chart.getCategoryPlot().getRangeAxis().setLabel("%");
        }
    }
}

From source file:ca.sqlpower.wabit.swingui.chart.effect.PieChartAnimator.java

@Override
protected void doFrame(int frame, double pct) {
    JFreeChart pieChart = mpplot.getPieChart();
    PiePlot plot = (PiePlot) pieChart.getPlot();

    plot.setStartAngle(spinInterpolator.value(initialAngle, finalAngle, pct));
    plot.setForegroundAlpha((float) alphaInterpolator.value(0.0, 1.0, pct));

    // need to trigger a repaint, because the pie plot is just a stamper
    mpplot.datasetChanged(new DatasetChangeEvent(pieChart, mpplot.getDataset()));
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of two Area Diagrams.
 * /*from  w  w  w . j  a  va2s.  co  m*/
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param doubles
 *          The array of values of the first array.
 * 
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createExpectedPowerChart(String title, String x, String y, double[] data) {
    JFreeChart chart = null;

    XYSeries series1 = new XYSeries("Expected Power");
    for (int i = 0; i < data.length; i++) {
        series1.add(i, data[i]);
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;

    chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setRange(0.0, 1440.0);
    domainAxis.setTickUnit(new NumberTickUnit(100));

    return new ChartPanel(chart);
}

From source file:net.sf.jasperreports.customizers.LevelRenderCustomizer.java

@Override
public void customize(JFreeChart jfc, JRChart jrc) {
    if (jfc.getPlot() instanceof CategoryPlot) {
        CategoryPlot plot = (CategoryPlot) jfc.getPlot();

        ItemsCounter itemsCounter = new CategoryCounter(plot);

        Integer seriesIndex = CustomizerUtil.resolveIndex(this, itemsCounter,
                new CategorySeriesNameProvider(plot));
        if (seriesIndex != null) {
            LevelRenderer levelRenderer = new LevelRenderer();

            Double itemMargin = getDoubleProperty(PROPERTY_ITEM_MARIGN);
            if (itemMargin != null) {
                levelRenderer.setItemMargin(itemMargin);
            }/*from ww w .j a  v a 2s.co  m*/
            Double maxItemWidth = getDoubleProperty(PROPERTY_MAX_ITEM_WIDTH);
            if (maxItemWidth != null) {
                levelRenderer.setMaximumItemWidth(maxItemWidth);
            }

            if (seriesIndex == -1) {
                for (int i = 0; i < itemsCounter.getCount(); i++) {
                    plot.setRenderer(i, levelRenderer);
                }
            } else {
                plot.setRenderer(seriesIndex, levelRenderer);
            }
        }
    }
}

From source file:ca.sqlpower.wabit.swingui.chart.effect.PieChartAnimatorFactory.java

public ChartAnimator createAnimator(JFreeChart chart) throws CantAnimateException {
    MultiplePiePlot mpplot;/*  w  w w . ja v  a 2 s.com*/
    if (chart.getPlot() instanceof MultiplePiePlot) {
        mpplot = (MultiplePiePlot) chart.getPlot();
    } else {
        throw new CantAnimateException(
                "This animator only works with MultiplePiePlot. " + "You gave me " + chart.getPlot());
    }

    return new PieChartAnimator(getFrameCount(), getFrameDelay(), mpplot, spinInterpolator, alphaInterpolator);
}