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:cv.mikusher.freechart.BubbleChart.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("AGE vs WEIGHT vs WORK", "Weight", "AGE", xyzdataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.65F);/*from  w w  w  . ja  v a2  s .c  o m*/
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setLowerMargin(0.2);
    numberaxis.setUpperMargin(0.5);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setLowerMargin(0.8);
    numberaxis1.setUpperMargin(0.9);

    return jfreechart;
}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("Bubble Chart Demo 2", "X", "Y", xyzdataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(new XYBubbleRenderer(0));
    xyplot.setForegroundAlpha(0.65F);//from w w w. j  av a2s  . c  o m
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    xyitemrenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator());
    xyitemrenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    xyitemrenderer.setBaseItemLabelsVisible(true);
    xyitemrenderer
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setRange(0.0D, 10D);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setRange(0.0D, 10D);
    return jfreechart;
}

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

public static JPanel createDemoPanel() {
    JPanel jpanel = new JPanel(new GridLayout(2, 2));
    jpanel.setPreferredSize(new Dimension(800, 600));
    IntervalXYDataset intervalxydataset = createDataset();
    JFreeChart jfreechart = createChart("Vertical", intervalxydataset);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(false);
    xybarrenderer.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    jpanel.add(chartpanel);/* w ww .  j av  a2 s  . c  om*/
    JFreeChart jfreechart1 = createChart("Vertical / Inverted Axis", intervalxydataset);
    XYPlot xyplot1 = (XYPlot) jfreechart1.getPlot();
    XYBarRenderer xybarrenderer1 = (XYBarRenderer) xyplot1.getRenderer();
    xybarrenderer1.setDrawBarOutline(false);
    xybarrenderer1.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer1.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer1.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    xyplot1.getDomainAxis().setInverted(true);
    ChartPanel chartpanel1 = new ChartPanel(jfreechart1);
    jpanel.add(chartpanel1);
    JFreeChart jfreechart2 = createChart("Horizontal", intervalxydataset);
    XYPlot xyplot2 = (XYPlot) jfreechart2.getPlot();
    xyplot2.setOrientation(PlotOrientation.HORIZONTAL);
    XYBarRenderer xybarrenderer2 = (XYBarRenderer) xyplot2.getRenderer();
    xybarrenderer2.setDrawBarOutline(false);
    xybarrenderer2.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer2.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer2.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    ChartPanel chartpanel2 = new ChartPanel(jfreechart2);
    jpanel.add(chartpanel2);
    JFreeChart jfreechart3 = createChart("Horizontal / Inverted Axis", intervalxydataset);
    XYPlot xyplot3 = (XYPlot) jfreechart3.getPlot();
    xyplot3.setOrientation(PlotOrientation.HORIZONTAL);
    XYBarRenderer xybarrenderer3 = (XYBarRenderer) xyplot3.getRenderer();
    xybarrenderer3.setDrawBarOutline(false);
    xybarrenderer3.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer3.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer3.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    xyplot3.getDomainAxis().setInverted(true);
    ChartPanel chartpanel3 = new ChartPanel(jfreechart3);
    jpanel.add(chartpanel3);
    return jpanel;
}

From source file:net.sf.maltcms.common.charts.api.ChartCustomizer.java

/**
 *
 * @param plot//from w ww. j a v  a 2s  .  co m
 * @param s
 */
public static void setSeriesShapes(XYPlot plot, Shape s) {
    XYItemRenderer renderer = plot.getRenderer();
    int series = plot.getSeriesCount();
    for (int i = 0; i < series; i++) {
        renderer.setSeriesShape(i, s);
    }
}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param p/*  ww  w . ja v  a2  s.  co m*/
 * @param sps
 */
public static void changePaintScale(final XYPlot p, final PaintScale sps) {
    if (p.getRenderer() instanceof XYBlockRenderer) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                XYBlockRenderer renderer = (XYBlockRenderer) p.getRenderer();
                Logger.getLogger(ChartTools.class.getName()).info("Setting paintscale");
                renderer.setPaintScale(sps);
                if (p instanceof FastHeatMapPlot) {
                    Logger.getLogger(ChartTools.class.getName()).info("Resetting data image");
                    FastHeatMapPlot fhp = (FastHeatMapPlot) p;
                    fhp.resetDataImage();
                }
                p.notifyListeners(new PlotChangeEvent(p));
            }
        };
        SwingUtilities.invokeLater(r);
    }
}

From source file:ChartPanelMaker.java

public static ChartPanel createChart(ArrayList<Voter> voters, ArrayList<Candidate> candidates,
        ArrayList<Candidate> committee, String title) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries comitteeDataset = new XYSeries("Committee");
    for (Candidate c : committee) {
        comitteeDataset.add(c.getX(), c.getY());
    }/*from  ww  w.ja va  2  s . c o  m*/
    dataset.addSeries(comitteeDataset);

    int n = voters.size();
    int m = candidates.size();

    int skipN = n / 150;
    if (skipN < 1) {
        skipN = 1;
    }

    int skipM = m / 150;
    if (skipM < 1) {
        skipM = 1;
    }

    Collections.sort(voters, Election.VoterNameComparator);
    Collections.sort(candidates, Election.CandidateNameComparator);

    XYSeries voterDataset = new XYSeries("Voters");
    for (int i = 0; i < n; i++) {
        Voter v = voters.get(i);
        if (i % skipN == 0) {
            voterDataset.add(v.getX(), v.getY());
        }
    }
    dataset.addSeries(voterDataset);

    XYSeries candidateDataset = new XYSeries("Candidates");
    for (int i = 0; i < m; i++) {
        Candidate c = candidates.get(i);
        if (i % skipM == 0) {
            candidateDataset.add(c.getX(), c.getY());
        }
    }
    dataset.addSeries(candidateDataset);

    Shape committeeShape = ShapeUtilities.createDiamond(5);
    Shape voterShape = ShapeUtilities.createDownTriangle(3);
    Shape candidateShape = ShapeUtilities.createUpTriangle(3);

    Color committeeColor = Color.DARK_GRAY;
    Color voterColor = Color.ORANGE;
    Color candidateColor = Color.LIGHT_GRAY;

    JFreeChart chart = ChartFactory.createScatterPlot(title, "", "", dataset, PlotOrientation.VERTICAL, true,
            true, true);
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer r = plot.getRenderer();
    r.setSeriesShape(0, committeeShape);
    r.setSeriesPaint(0, committeeColor);
    r.setSeriesShape(1, voterShape);
    r.setSeriesPaint(1, voterColor);
    r.setSeriesShape(2, candidateShape);
    r.setSeriesPaint(2, candidateColor);
    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:mt.DisplayHistogram.java

protected static JFreeChart createChart(final IntervalXYDataset dataset, final String title,
        final String units) {
    final JFreeChart chart = ChartFactory.createXYBarChart(title, "Lifetime [" + units + "]", false, "Count",
            dataset, PlotOrientation.VERTICAL, false, // legend
            false, false);//from ww w .j av a2s . c  o m

    NumberAxis range = (NumberAxis) chart.getXYPlot().getDomainAxis();
    range.setRange(getMin(), getMax());

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();

    renderer.setSeriesPaint(0, Color.red);
    renderer.setDrawBarOutline(true);
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setBarPainter(new StandardXYBarPainter());

    return chart;
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param plot/*from   www. ja  v  a  2  s. c om*/
 * @param alpha
 */
public static void setSeriesColors(XYPlot plot, float alpha) {
    XYItemRenderer renderer = plot.getRenderer();
    int series = plot.getSeriesCount();
    for (int i = 0; i < series; i++) {
        renderer.setSeriesPaint(i, withAlpha(plotColors[i % plotColors.length], alpha));
    }
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param plot//from   w  w w  . j ava 2  s  .c o  m
 * @param width
 */
public static void setSeriesStrokes(XYPlot plot, float width) {
    XYItemRenderer renderer = plot.getRenderer();
    int series = plot.getSeriesCount();
    for (int i = 0; i < series; i++) {
        renderer.setSeriesStroke(i, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    }
}

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsTotalPrediction.java

public static JPanel createPanel() {
    //Axis configuration
    NumberAxis sampleAxis = new NumberAxis("Sample");
    sampleAxis.setAutoRangeIncludesZero(false);
    NumberAxis powerAxis = new NumberAxis("Power (Watts)");
    powerAxis.setAutoRangeIncludesZero(false);

    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();

    XYPlot xyplot = new XYPlot(data, sampleAxis, powerAxis, xysplinerenderer);
    for (int i = 0; i < data.getSeriesCount(); i++) {
        xyplot.getRenderer().setSeriesShape(i, new Rectangle());
    }//  w w  w  .ja  v  a2 s  . co  m

    //Panel layout configuration
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

    JFreeChart jfreechart = new JFreeChart(NAME, JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);

    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart);

    return chartpanel;
}