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:ec.ui.view.res.ResidualsView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(themeSupport.getAreaColor(MAIN_COLOR));
    renderer.setBaseOutlinePaint(themeSupport.getLineColor(MAIN_COLOR));
}

From source file:edu.ucla.stat.SOCR.chart.SuperXYChart.java

protected JFreeChart createLegend(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // url
    );//  ww w . ja v a 2 s  .  c o  m

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;

}

From source file:com.att.aro.main.PacketPlots.java

/**
 * Creates the XYIntervalSeries for the uplink and downlink packets plot.
 * //from   w  ww.  j  ava 2  s.c om
 * @param plot
 *            The XYPlot for the uplink/downlink plots.
 * @param dataset
 *            The uplink/downlink datasets.
 */
private void populatePacketPlot(XYPlot plot, LinkedHashMap<Color, PacketSeries> dataset) {

    // Create the XY data set
    YIntervalSeriesCollection coll = new YIntervalSeriesCollection();
    XYItemRenderer renderer = plot.getRenderer();
    for (PacketSeries series : dataset.values()) {
        coll.addSeries(series);

        renderer.setSeriesPaint(coll.indexOf(series.getKey()), series.getColor());
    }

    // Create tooltip generator
    renderer.setBaseToolTipGenerator(new PacketToolTipGenerator());

    plot.setDataset(coll);
}

From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java

/**
 * /*from  w w w.  j  ava  2  s .com*/
 * @param clusters
 */
public static void buildKMeansChart(final List<Instances> clusters) {
    final XYSeriesCollection dataset = new XYSeriesCollection();

    final JFreeChart chart = ChartFactory.createScatterPlot("", // title 
            "X", "Y", // axis labels 
            dataset, // dataset 
            PlotOrientation.VERTICAL, true, // legend? yes 
            true, // tooltips? yes 
            false // URLs? no 
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();

    ((NumberAxis) xyPlot.getDomainAxis()).setTickUnit(new NumberTickUnit(2.0));
    ((NumberAxis) xyPlot.getRangeAxis()).setTickUnit(new NumberTickUnit(2.0));

    Attribute clsAttribute = null;
    int nbClass = 1;
    Instances cluster0 = clusters.get(0);
    if (cluster0.classIndex() != -1) {
        clsAttribute = cluster0.classAttribute();
        nbClass = clsAttribute.numValues();
    }
    if (nbClass <= 1) {
        dataset.addSeries(new XYSeries("Serie #1", false));
    } else {
        for (int i = 0; i < nbClass; i++) {
            dataset.addSeries(new XYSeries(clsAttribute.value(i), false));
        }
    }

    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "TODO";
        }
    };

    for (int i = 0; i < nbClass; i++) {
        dataset.getSeries(i).clear();
        xyPlot.getRenderer().setSeriesToolTipGenerator(i, gen);
    }

    final int nbClusters = clusters.size();
    for (int i = 0; i < nbClusters; i++) {
        Instances instances = clusters.get(i);
        final int nbInstances = instances.numInstances();
        for (int j = 0; j < nbInstances; j++) {
            final Instance oInst = instances.instance(j);
            dataset.getSeries(i).add(oInst.value(0), oInst.value(1));
        }
    }

    final TitledBorder titleBorder = new TitledBorder("Kmeans of projection");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(new Dimension(1200, 900));
    chartPanel.setBorder(titleBorder);
    chartPanel.setBackground(Color.WHITE);

    JXFrame frame = new JXFrame();
    frame.getContentPane().add(chartPanel);
    frame.setVisible(true);
    frame.pack();

}

From source file:org.geotoolkit.gui.swing.propertyedit.styleproperty.JAnalizePanel.java

public JFreeChart getChart(final int nbDivision) {
    XYSeries series = new XYSeries("Data");

    double before = analyze.getMinimum();
    for (float i = 1; i <= nbDivision; i++) {
        final double localmin = before;
        final double localmax = analyze.getMinimum()
                + (i / nbDivision) * (analyze.getMaximum() - analyze.getMinimum());
        before = localmax;//ww  w  .j a v  a2 s .  c  o m
        long localsum = 0;

        for (Double d : analyze.getAllValues()) {
            if (i == 100) {
                //last element
                if (d >= localmin && d <= localmax) {
                    localsum++;
                }
            } else {
                if (d >= localmin && d < localmax) {
                    localsum++;
                }
            }
        }
        series.add(analyze.getMinimum() + (localmin + localmax) / 2, localsum);
    }

    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart chart = ChartFactory.createXYBarChart("", "", false, "", dataset, PlotOrientation.VERTICAL,
            false, false, false);

    XYPlot plot = chart.getXYPlot();
    ((XYBarRenderer) plot.getRenderer()).setShadowVisible(false);
    ((XYBarRenderer) plot.getRenderer()).setUseYInterval(false);
    ((XYBarRenderer) plot.getRenderer()).setMargin(0);

    chart.getPlot().setBackgroundAlpha(0);
    chart.setBackgroundPaint(new Color(0f, 0f, 0f, 0f));

    return chart;
}

From source file:org.jfree.chart.demo.TimeSeriesDemo.java

/**
 * Creates a chart.//from w w w  .  jav  a 2 s . c  o  m
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", dataset, true, true, false);

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //        sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        rr.setItemLabelsVisible(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}

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

/**
 * Creates a chart./*from w w w .ja  v  a2  s  . com*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

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

    setXSummary(dataset);
    return chart;

}

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

/**
 * Creates a chart.//from  w  w  w.j  a  va2 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, // chart title
            domainLabel, // x axis label 
            rangeLabel, // y axis label  
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // 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.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
    renderer.setBaseLinesVisible(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.05);
    rangeAxis.setLowerMargin(0.05);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    //  domainAxis.setTickLabelsVisible(false);
    // domainAxis.setTickMarksVisible(false);      
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    return chart;
}

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

private void createChart() {

    _chart = ChartFactory.createXYAreaChart(Misc.getString("LIBRARY_GROWTH"), Misc.getString("DATE"),
            Misc.getString("SONGS_IN_LIBRARY"), _dataset, PlotOrientation.VERTICAL, false, // legend
            true, // tool tips
            false // URLs
    );//  w  w  w .  j  ava  2s.  c om
    XYPlot plot = (XYPlot) _chart.getPlot();
    plot.setDomainPannable(true);
    ValueAxis domainAxis = new DateAxis(Misc.getString("TIME"));
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.75f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("#,##0.00")));

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

    ChartUtilities.applyCurrentTheme(_chart);
    Misc.formatChart(plot);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    renderer.setSeriesPaint(0, Theme.getColorSet()[1]);

}

From source file:org.jfree.chart.demo.TimeSeriesDemo12.java

/**
 * Creates a chart./*  w  w w  .j  a  v  a 2s  .  c  o  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sample Chart", "Date", "Value", dataset, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //      sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    //plot.setOutlinePaint(null);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(false);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        renderer.setSeriesStroke(0, new BasicStroke(2.0f));
        renderer.setSeriesStroke(1, new BasicStroke(2.0f));
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mma"));

    return chart;

}