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:com.globalsight.util.JfreeCharUtil.java

public static void drawPieChart2D(String title, Map<String, Double> datas, File OutFile) {
    PieDataset dataset = buildDatas(datas);
    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
    chart.setBackgroundPaint(Color.white);
    plot.setCircular(true);//from w w  w. j  av  a2  s . c  o m
    TextTitle textTitle = new TextTitle(title);
    Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20);
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    FileOutputStream fos_jpg = null;

    try {
        fos_jpg = new FileOutputStream(OutFile);
        ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null);
        fos_jpg.close();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
    }
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createPolarChart("Polar Chart Demo 1", xydataset, true, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    PolarPlot polarplot = (PolarPlot) jfreechart.getPlot();
    polarplot.setBackgroundPaint(Color.lightGray);
    polarplot.addCornerTextItem("Corner Item 1");
    polarplot.addCornerTextItem("Corner Item 2");
    polarplot.setAngleGridlinePaint(Color.white);
    polarplot.setRadiusGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) polarplot.getAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLine3DRenderer Demo 1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYLine3DRenderer xyline3drenderer = new XYLine3DRenderer();
    xyline3drenderer.setWallPaint(Color.gray);
    xyline3drenderer.setXOffset(2D);//from w ww  . ja v a2  s  .  c o  m
    xyline3drenderer.setYOffset(3D);
    xyline3drenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xyline3drenderer.setDefaultEntityRadius(6);
    xyplot.setRenderer(xyline3drenderer);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setSeriesLinesVisible(0, true);
    xylineandshaperenderer.setSeriesShapesVisible(0, false);
    xylineandshaperenderer.setSeriesLinesVisible(1, false);
    xylineandshaperenderer.setSeriesShapesVisible(1, true);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xylineandshaperenderer.setDefaultEntityRadius(6);
    xyplot.setRenderer(xylineandshaperenderer);
    return jfreechart;
}

From source file:com.globalsight.util.JfreeCharUtil.java

public static void drawPieChart3D(String title, Map<String, Double> datas, File OutFile) {
    PieDataset dataset = buildDatas(datas);
    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
    chart.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.7f);/*www.  j a va2  s  .  c o  m*/
    plot.setCircular(true);
    TextTitle textTitle = new TextTitle(title);
    Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20);
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    FileOutputStream fos_jpg = null;

    try {
        fos_jpg = new FileOutputStream(OutFile);
        ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null);
        fos_jpg.close();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
    }
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYStepRenderer Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    ValueAxis valueaxis = xyplot.getRangeAxis();
    valueaxis.setUpperMargin(0.14999999999999999D);
    XYStepRenderer xysteprenderer = new XYStepRenderer();
    xysteprenderer.setSeriesStroke(0, new BasicStroke(2.0F));
    xysteprenderer.setSeriesStroke(1, new BasicStroke(2.0F));
    xysteprenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xysteprenderer.setDefaultEntityRadius(6);
    xysteprenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    xysteprenderer.setBaseItemLabelsVisible(true);
    xysteprenderer.setBaseItemLabelFont(new Font("Dialog", 1, 14));
    xyplot.setRenderer(xysteprenderer);/*from   w ww .  j  a  v  a  2s .c o  m*/
    return jfreechart;
}

From source file:umberto.WeightedClusterCoefficient.ChartUtils.java

public static void scaleLogarithmicChart(JFreeChart chart, XYSeries dSeries, boolean normalized) {
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis logxaxis = new LogarithmicAxis(plot.getDomainAxis().getLabel());
    NumberAxis logyaxis = new LogarithmicAxis(plot.getRangeAxis().getLabel());
    plot.setRangeAxis(logyaxis);/*from w w w. j  a  v  a 2s  .  co  m*/
    plot.setDomainAxis(logxaxis);
}

From source file:eu.delving.sip.base.ReportChartHelper.java

private static JPanel finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangePannable(true);//from w ww.j  a  v a  2s.  c o m
    if (colors.length > 0)
        plot.setRenderer(new CustomRenderer(colors));
    BarRenderer bar = (BarRenderer) plot.getRenderer();
    bar.setItemLabelAnchorOffset(9D);
    bar.setBaseItemLabelsVisible(true);
    bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bar.setMaximumBarWidth(0.05);
    bar.setItemMargin(0.03D);
    bar.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D));
    bar.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D));
    CategoryAxis x = plot.getDomainAxis();
    x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    x.setCategoryMargin(0.25D);
    x.setUpperMargin(0.02D);
    x.setLowerMargin(0.02D);
    NumberAxis y = (NumberAxis) plot.getRangeAxis();
    y.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    y.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return new ChartPanel(chart);
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDirectionDataset(600);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", xydataset, true,
            true, false);/*from   w ww . jav a  2s  . c  o m*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.getDomainAxis().setLowerMargin(0.0D);
    xyplot.getDomainAxis().setUpperMargin(0.0D);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    TickUnits tickunits = new TickUnits();
    tickunits.add(new NumberTickUnit(180D, new CompassFormat()));
    tickunits.add(new NumberTickUnit(90D, new CompassFormat()));
    tickunits.add(new NumberTickUnit(45D, new CompassFormat()));
    tickunits.add(new NumberTickUnit(22.5D, new CompassFormat()));
    numberaxis.setStandardTickUnits(tickunits);
    xyplot.setRangeAxis(numberaxis);
    XYAreaRenderer xyarearenderer = new XYAreaRenderer();
    NumberAxis numberaxis1 = new NumberAxis("Force");
    numberaxis1.setRange(0.0D, 12D);
    xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128));
    xyplot.setDataset(1, createForceDataset(600));
    xyplot.setRenderer(1, xyarearenderer);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    return jfreechart;
}

From source file:audio.cords.old.RegressionDemo.java

private static JFreeChart createChart(XYSeriesCollection data) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "X", "Y", data, PlotOrientation.VERTICAL, true,
            false, false);//from w  w  w  .j  av a 2  s .c om
    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer scatterRenderer = plot.getRenderer();
    StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer();
    regressionRenderer.setBaseSeriesVisibleInLegend(false);
    plot.setDataset(1, regress(data));
    plot.setRenderer(1, regressionRenderer);
    DrawingSupplier ds = plot.getDrawingSupplier();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        Paint paint = ds.getNextPaint();
        scatterRenderer.setSeriesPaint(i, paint);
        regressionRenderer.setSeriesPaint(i, paint);
    }
    return chart;
}