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.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYAreaChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYAreaChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w w  w.  j a v a2 s.  c  o m*/

    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.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYStepChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYStepChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w w w  .  ja v  a2 s.c  om*/

    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);

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

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createScatterChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createScatterPlot("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   w ww. j a  va 2 s. c  o m*/

    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.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;

}

From source file:unalcol.termites.boxplots.SucessfulRatesHybrid.java

private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18));
    jfreechart.setBackgroundPaint(new Color(221, 223, 238));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    //categoryplot.setBackgroundPaint(new Color(221, 223, 238));

    renderer.setSeriesPaint(0, new Color(130, 165, 70));
    renderer.setSeriesPaint(1, new Color(220, 165, 70));
    renderer.setSeriesPaint(4, new Color(255, 165, 70));
    renderer.setDrawBarOutline(false);/*from   w ww .  j av  a  2s.c  o  m*/
    renderer.setShadowVisible(false);
    // renderer.setMaximumBarWidth(1);
    renderer.setGradientPaintTransformer(null);
    renderer.setDefaultBarPainter(new StandardBarPainter());

    categoryplot.setRenderer(renderer);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.25D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null));
    numberaxis.setRange(0, 100);
    //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
    numberaxis.setTickLabelFont(font);
    CategoryAxis axisd = categoryplot.getDomainAxis();
    ValueAxis axisr = categoryplot.getRangeAxis();
    axisd.setTickLabelFont(font);
    axisr.setTickLabelFont(font);

    axisd.setMaximumCategoryLabelLines(5);

    final ChartPanel chartPanel = new ChartPanel(jfreechart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1300, 370));

    FileOutputStream output;
    try {
        output = new FileOutputStream("sucessrates1" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 1300, 370, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);//from   w w w  .ja v  a 2 s  .  c o  m
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.14999999999999999D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    lineandshaperenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java

private static ChartPanel createChart(String title, String y_axis, XYDataset dataset, boolean createLegend) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            y_axis, // y-axis label
            dataset, // data
            createLegend, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );//from  ww w . j av  a 2 s .  c o m

    chart.setBackgroundPaint(Color.white);

    final 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);

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

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

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM. HH:mm"));

    return new ChartPanel(chart);

}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );/*from   w w  w  . j  a v  a  2s  . com*/

    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);

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

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

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYStepAreaChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYStepAreaChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );//from   w  w w.  j  a  va2 s  .  c om

    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.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/* w  w  w .  j a va2 s  .c o m*/
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryPointerAnnotation categorypointerannotation = new CategoryPointerAnnotation("Released 4-Dec-1998",
            "JDK 1.2", 1530D, -2.3561944901923448D);
    categorypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    categoryplot.addAnnotation(categorypointerannotation);
    return jfreechart;
}

From source file:lu.lippmann.cdb.datasetview.tabs.ScatterPlotTabView.java

private static ChartPanel buildChartPanel(final Instances dataSet, final int xidx, final int yidx,
        final int coloridx, final boolean asSerie) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final Map<Integer, List<Instance>> filteredInstances = new HashMap<Integer, List<Instance>>();
    final int classIndex = dataSet.classIndex();
    if (classIndex < 0) {
        final XYSeries series = new XYSeries("Serie", false);
        for (int i = 0; i < dataSet.numInstances(); i++) {
            series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));

        }//from  ww w.  j  av a2s  . c om
        data.addSeries(series);
    } else {
        final Set<String> pvs = WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex);
        int p = 0;
        for (final String pv : pvs) {
            final XYSeries series = new XYSeries(pv, false);
            for (int i = 0; i < dataSet.numInstances(); i++) {
                if (dataSet.instance(i).stringValue(classIndex).equals(pv)) {
                    if (!filteredInstances.containsKey(p)) {
                        filteredInstances.put(p, new ArrayList<Instance>());
                    }
                    filteredInstances.get(p).add(dataSet.instance(i));

                    series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
                }
            }
            data.addSeries(series);

            p++;
        }

    }

    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title
            dataSet.attribute(xidx).name(), // x axis label
            dataSet.attribute(yidx).name(), // y axis label
            data, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();
    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(final XYDataset dataset, final int series, final int item) {
            if (classIndex < 0) {
                return InstanceFormatter.htmlFormat(dataSet.instance(item), true);
            } else {
                return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true);
            }
        }
    };

    int nbSeries;
    if (classIndex < 0) {
        nbSeries = 1;
    } else {
        nbSeries = filteredInstances.keySet().size();
    }

    final XYItemRenderer renderer = new XYLineAndShapeRenderer(asSerie, true) {
        /** */
        private static final long serialVersionUID = 1L;

        @Override
        public Paint getItemPaint(final int row, final int col) {
            //System.out.println(row+" "+col);
            if (classIndex < 0) {
                final double v = dataSet.instance(col).value(coloridx);
                final double[] minmax = WekaDataStatsUtil.getMinMaxForAttributeAsArrayOfDoubles(dataSet,
                        coloridx);

                final double rated = (v - minmax[0]) / (minmax[1] - minmax[0]);
                System.out.println("rated -> " + rated + " min=" + minmax[0] + "max=" + minmax[1]);
                final int colorIdx = (int) Math.round((ColorHelper.YlGnBu_9_COLORS.length - 1) * rated);

                //System.out.println(minmax[0]+" "+minmax[1]+" "+v+" "+rated+" "+colorIdx);
                return ColorHelper.YlGnBu_9_COLORS[colorIdx];
            } else
                return super.getItemPaint(row, col);
        }
    };
    xyPlot.setRenderer(renderer);

    for (int i = 0; i < nbSeries; i++) {
        renderer.setSeriesToolTipGenerator(i, gen);
    }

    return new ChartPanel(chart);
}