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

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

Introduction

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

Prototype

public XYItemRenderer getRenderer() 

Source Link

Document

Returns the renderer for the primary dataset.

Usage

From source file:adams.flow.sink.JFreeChartPlot.java

/**
 * Creates a new display panel for the token.
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel//from ww  w  .j  a  va  2s . c  o  m
 */
@Override
public DisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;

    result = new AbstractComponentDisplayPanel(getClass().getSimpleName()) {
        private static final long serialVersionUID = -3785685146120118884L;
        protected JFreeChart m_JFreeChart;
        protected ChartPanel m_PlotPanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
        }

        @Override
        public void display(Token token) {
            SpreadSheet sheet = (SpreadSheet) token.getPayload();
            Dataset dataset = m_Dataset.generate(sheet);
            m_JFreeChart = m_Chart.generate(dataset);
            if (m_JFreeChart.getPlot() instanceof XYPlot) {
                XYPlot plot = (XYPlot) m_JFreeChart.getPlot();
                plot.setDomainGridlinesVisible(true);
                plot.setDomainGridlinePaint(Color.GRAY);
                plot.setRangeGridlinesVisible(true);
                plot.setRangeGridlinePaint(Color.GRAY);
                plot.getRenderer().setSeriesPaint(0, m_PlotColor);
                if (plot.getSeriesCount() > 1)
                    plot.getRenderer().setSeriesPaint(1, m_DiagonalColor);
                Shape shape = m_Shape.generate();
                if (shape != null)
                    plot.getRenderer().setSeriesShape(0, shape);
            }
            m_PlotPanel = new ChartPanel(m_JFreeChart);
            removeAll();
            add(m_PlotPanel, BorderLayout.CENTER);
        }

        @Override
        public void clearPanel() {
            removeAll();
            m_JFreeChart = null;
        }

        @Override
        public void cleanUp() {
            removeAll();
            m_JFreeChart = null;
        }

        @Override
        public JComponent supplyComponent() {
            return m_PlotPanel;
        }
    };

    if (token != null)
        result.display(token);

    return result;
}

From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java

@Override
protected JFreeChart createBubbleChart() throws JRException {
    JFreeChart jfreeChart = super.createBubbleChart();

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    XYBubbleRenderer bubbleRenderer = (XYBubbleRenderer) xyPlot.getRenderer();
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            bubbleRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }/*from   ww  w  . ja va2s  .c om*/
    }
    return jfreeChart;
}

From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java

@Override
protected JFreeChart createCandlestickChart() throws JRException {
    JFreeChart jfreeChart = super.createCandlestickChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    CandlestickRenderer renderer = (CandlestickRenderer) xyPlot.getRenderer();
    DefaultHighLowDataset dataset = (DefaultHighLowDataset) xyPlot.getDataset();
    @SuppressWarnings("unchecked")
    List<Paint> seriesPaints = (List<Paint>) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SERIES_COLORS);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {

        renderer.setSeriesFillPaint(i, seriesPaints.get(i));
        renderer.setSeriesPaint(i, Color.DARK_GRAY);
    }/*from  www.  j  ava 2  s . c o m*/
    return jfreeChart;
}

From source file:charts.Chart.java

public static void MultipleLineChart(XYSeriesCollection datasets, String title, String x_axis_label,
        String y_axis_label) {/*  w w  w .  ja  v  a  2s .  co  m*/
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createXYLineChart(title, x_axis_label, y_axis_label, datasets,
            PlotOrientation.VERTICAL, true, true, true);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.black);

    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    XYLineAndShapeRenderer lineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    lineandshaperenderer.setShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setFillPaint(Color.white);

    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}

From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformXYScatterChart.java

/**
 * Creates a chart./*w  w w  . j a  v a 2  s .  c o  m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Power Transformed XYScatter Chart",      // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    // renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0);
    rangeAxis.setLowerMargin(0);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setXSummary(dataset);
    return chart;

}

From source file:org.jgrasstools.gears.utils.chart.Scatter.java

public JFreeChart getChart() {
    if (chart == null) {
        chart = ChartFactory.createXYLineChart(title, // chart title
                xLabel,/*w  w w. j a  v  a 2s  .  c  o  m*/
                // domain axis label
                yLabel,
                // range axis label
                dataset,
                // data
                PlotOrientation.VERTICAL,
                // orientation
                false,
                // include legend
                true,
                // tooltips?
                false
        // URLs?
        );

        XYPlot plot = (XYPlot) chart.getPlot();
        if (xLog) {
            LogAxis xAxis = new LogAxis("");
            xAxis.setBase(10);
            plot.setDomainAxis(xAxis);
        }
        if (yLog) {
            LogAxis yAxis = new LogAxis("");
            yAxis.setBase(10);
            plot.setRangeAxis(yAxis);
        }

        ValueAxis rangeAxis = plot.getRangeAxis();
        if (rangeAxis instanceof NumberAxis) {
            NumberAxis axis = (NumberAxis) rangeAxis;
            axis.setAutoRangeIncludesZero(false);
        }

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        double x = 1.5;
        double w = x * 2;
        renderer.setSeriesShape(0, new Ellipse2D.Double(-x, x, w, w));
        setShapeLinesVisibility(plot);
    }
    return chart;
}

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

/**
 * Creates a line chart./*ww w . j  a  v a  2  s  .  c o m*/
 * 
 * @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:slash.navigation.converter.gui.profileview.ProfileView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setForegroundAlpha(0.65F);/*from   w ww .j av  a2 s. c  o  m*/
    plot.setDomainGridlinesVisible(preferences.getBoolean(X_GRID_PREFERENCE, true));
    plot.setRangeGridlinesVisible(preferences.getBoolean(Y_GRID_PREFERENCE, true));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(createIntegerTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(createIntegerTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    plot.getRenderer().setBaseToolTipGenerator(null);
    return plot;
}