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.leonarduk.finance.chart.BollingerBars.java

public static void displayBollingerBars(final Stock stock) throws IOException {
    final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1);

    /**//from   w ww  .  ja  v a2s .  co  m
     * Creating indicators
     */
    // Close price
    final ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    // Bollinger bands
    final BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(closePrice);
    final BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, closePrice,
            Decimal.ONE);
    final BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, closePrice,
            Decimal.ONE);

    /**
     * Building chart dataset
     */
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(BollingerBars.buildChartTimeSeries(series, closePrice,
            stock.getName() + ". (" + stock.getSymbol() + ") - " + stock.getStockExchange()));
    dataset.addSeries(BollingerBars.buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
    dataset.addSeries(BollingerBars.buildChartTimeSeries(series, upBBand, "High Bollinger Band"));

    /**
     * Creating the chart
     */
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(stock.getName() + "Close Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    final XYPlot plot = (XYPlot) chart.getPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));

    /**
     * Displaying the chart
     */
    ChartDisplay.displayChartInFrame(chart, 500, 270, "Bollinger chart");
}

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

private static JFreeChart createChart1(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo 1", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
    return jfreechart;
}

From source file:st.jigasoft.dbutil.util.ReportTheme.java

public static void circularTheme(JFreeChart chart, String... colunsName) {
    chart.setBackgroundPaint(/*from  w  w w  .j av a  2  s.  c o  m*/
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);
    int iCount = 0;

    // use gradients and white borders for the section colours
    for (Object s : colunsName) {
        plot.setSectionPaint(s.toString(), createGradientPaint(new Color(200, 200, 255), colorItems(iCount++)));
        if (iCount == MAX_COLUNS_COLOR)
            iCount = 0;
    }

    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    //        // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
}

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

private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) {
    //        createPieChart(String title,
    //                PieDataset dataset,
    //                PieDataset previousDataset,
    //                int percentDiffForMaxScale,
    //                boolean greenForIncrease,
    //                boolean legend,
    //                boolean tooltips,
    //                boolean urls,
    //                boolean subTitle,
    //                boolean showDifference)
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", // chart title
            dataset, // data
            previousDataset, 0, // percentDiffForMaxScale
            true, // greenForIncrease
            true, // include legend
            true, // tooltips
            false, // urls
            true, // subTitle
            true); // showDifference

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage("No data available");

    return chart;

}

From source file:com.windows.Chart.java

public static JFreeChart createChart(XYDataset dataset) {
    //   /*from w w w  .j a v  a2 s .  c  o m*/
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLine Chart Demo", //    
            "??", // categoryAxisLabel categoryX      
            "?", // valueAxisLabelvalueY      
            dataset, // dataset      
            PlotOrientation.VERTICAL, true, // legend      
            false, // tooltips      
            false); // URLs   
    // CategoryPlot?????      
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    //  ?      
    plot.setBackgroundAlpha(0.5f);
    return jfreechart;
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for creating a pie chart of a Person Model's
 * statistical attributes./*from  w  w w  .  jav  a2 s  . com*/
 * 
 * @param title
 *          The chart's title
 * @param person
 *          The person under consideration
 * 
 * @return a chart panel with the statistical graphical representation.
 */
public static ChartPanel createPieChart(String title, Person person) {

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Activity Models", person.getActivityModelsSize());
    dataset.setValue("Response Models", person.getResponseModelsSize());

    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, true);

    PiePlot plot = (PiePlot) chart.getPlot();
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);

    return new ChartPanel(chart);
}

From source file:com.decypher.threadsclient.ChartProvider.java

/**
 * ****** End of Dashboard Charts **********
 *//*from w ww  .  j  a  va 2 s  .c om*/
public static JPanelChart addChart(JFreeChart chart, String title) {
    chart.getPlot().setBackgroundPaint(Color.LIGHT_GRAY);
    chart.setBackgroundPaint(SystemColor.control);
    ChartPanel cpnl = new ChartPanel(chart);
    JPanelChart pnl = new JPanelChart(chart);
    pnl.setLayout(new BorderLayout());
    pnl.setPreferredSize(new Dimension(getMaxWidth(), maxHeight));
    pnl.add(cpnl, BorderLayout.CENTER);
    pnl.setName(title);
    return pnl;
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel,
        int pointRadius, int lineThickness, ColorTheme theme) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL,
            true, false, false);//  w w  w . ja  v  a  2s.  c  om

    formatColorTheme(chart, theme);

    XYPlot plot = (XYPlot) chart.getPlot();
    Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    Color[] colors = generateJetSpectrum(data.getSeriesCount());
    for (int i = 0; i < data.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness));
        plot.getRenderer().setSeriesShape(i, icon);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true);
        plot.getRenderer().setSeriesPaint(i, colors[i]);
    }

    LegendTitle legend = chart.getLegend();
    Font legendFont = legend.getItemFont();
    float legendFontSize = legendFont.getSize();
    Font newLegendFont = legendFont.deriveFont(legendFontSize * 0.6f);
    legend.setItemFont(newLegendFont);

    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Font domainAxisLabelFont = domainAxis.getLabelFont();
    float domainAxisLabelFontSize = domainAxisLabelFont.getSize();
    domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f));

    Font domainAxisTickLabelFont = domainAxis.getTickLabelFont();
    float domainAxisTickLabelFontSize = domainAxisTickLabelFont.getSize();
    domainAxis.setTickLabelFont(domainAxisTickLabelFont.deriveFont(domainAxisTickLabelFontSize * 0.6f));

    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    Font rangeAxisLabelFont = rangeAxis.getLabelFont();
    float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize();
    rangeAxis.setLabelFont(rangeAxisLabelFont.deriveFont(rangeAxisLabelFontSize * 0.6f));

    Font rangeAxisTickLabelFont = rangeAxis.getTickLabelFont();
    float rangeAxisTickLabelFontSize = rangeAxisTickLabelFont.getSize();
    rangeAxis.setTickLabelFont(rangeAxisTickLabelFont.deriveFont(rangeAxisTickLabelFontSize * 0.6f));

    return chart;
}

From source file:service.chart.FitnessChart.java

/**
 * Utworz wykres funkcji fitness dla najlepszego osobnika w danej iteracji algorytmu genetycznego 
 * na podstawie zestawu danych/* www .  ja va  2s  . c om*/
 * 
 * @param categoryDataset Zestaw danych
 * @return Wykres funkcji fitness
 */
private static JFreeChart createChart(CategoryDataset categoryDataset) {

    JFreeChart chart = ChartFactory.createLineChart("Best fitness function value", // title
            "Iteration", // x-axis label
            "Fitness", // y-axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    CategoryItemRenderer r = plot.getRenderer();
    if (r instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer renderer = (LineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(true);
    }

    return chart;
}

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

/**
 * Creates a chart./*from ww w . j  a v  a2 s  .  c o  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(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?
    );

    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.setDefaultShapesVisible(true);
        renderer.setDefaultShapesFilled(true);
    }

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

    return chart;

}