Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart JFreeChart.

Prototype

public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.Thermometer.java

/**
 * Creates a chart of type thermometer.//www .  j  ava  2  s  .  c  om
 * 
 * @return A chart thermometer.
 */
public JFreeChart createChart() {
    logger.debug("IN");

    if (dataset == null) {
        logger.debug("The dataset to be represented is null");
        return null;
    }

    ThermometerPlot plot = new ThermometerPlot((ValueDataset) dataset);
    logger.debug("Created the new Thermometer Plot");
    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    logger.debug("Created the new Chart");
    chart.setBackgroundPaint(color);
    logger.debug("Setted the background color of the chart");

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    logger.debug("Setted the title of the chart");
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
        logger.debug("Setted the subtitle of the chart");
    }

    plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setPadding(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Color.lightGray);
    plot.setGap(3);
    plot.setValueLocation(3);
    plot.setRange(lower, upper);
    plot.setUnits(ThermometerPlot.UNITS_NONE);
    logger.debug("Setted all the properties of the plot");

    // set subranges   
    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval subrange = (KpiInterval) iterator.next();
        int range = 0;
        //For the thermometer the number of intervals is forced to 3 and they have to have as labels the following ones
        if (subrange.getLabel().equalsIgnoreCase("NORMAL"))
            range = (ThermometerPlot.NORMAL);
        else if (subrange.getLabel().equalsIgnoreCase("WARNING"))
            range = (ThermometerPlot.WARNING);
        else if (subrange.getLabel().equalsIgnoreCase("CRITICAL"))
            range = (ThermometerPlot.CRITICAL);

        plot.setSubrange(range, subrange.getMin(), subrange.getMax());
        if (subrange.getColor() != null) {
            plot.setSubrangePaint(range, subrange.getColor());
        }
        logger.debug("Setted new range of the plot");
    }

    logger.debug("OUT");
    return chart;
}

From source file:org.sonar.api.charts.AbstractChart.java

/**
 * Generates a JFreeChart chart using a set of parameters
 * //from  ww w  .  jav a 2 s . co m
 * @param params the chart parameters
 * @return the generated chart
 */
public BufferedImage generateImage(ChartParameters params) {
    JFreeChart chart = new JFreeChart(null, TextTitle.DEFAULT_FONT, getPlot(params), hasLegend());
    improveChart(chart, params);
    return chart.createBufferedImage(params.getWidth(), params.getHeight());
}

From source file:moviedatas.View.SpiderWebChart.java

/**
 * Creates a sample chart./*from w ww.j a  v a2  s. c  o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    SpiderWebPlot plot = new SpiderWebPlot(dataset);
    plot.setStartAngle(54);
    plot.setInteriorGap(0.40);
    //plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, false);
    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);
    //ChartUtilities.applyCurrentTheme(chart);
    return chart;
}

From source file:control.JGeraGraficos.java

private static JFreeChart createGraficoXY(String title, String categoryAxisLabel, String valueAxisLabel,
        IntervalXYDataset dataset) {/*www.  ja  va 2  s . c om*/

    NumberAxis domainAxis = new NumberAxis(categoryAxisLabel);
    domainAxis.setAutoRangeIncludesZero(false);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    XYBarRenderer renderer = new ClusteredXYBarRenderer();

    XYPlot plot = new XYPlot((XYDataset) dataset, domainAxis, valueAxis, renderer);

    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaChartExpression.java

public static JFreeChart createTimeSeriesChart(final String title, final String timeAxisLabel,
        final String valueAxisLabel, final XYDataset dataset, final boolean legend, final boolean tooltips,
        final boolean urls, final boolean stacked) {
    final ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);/* www.j a va2s .  c  o  m*/
    final NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    final XYAreaRenderer2 renderer;
    if (stacked) {
        renderer = new StackedXYAreaRenderer2();
    } else {
        renderer = new XYAreaRenderer2();
    }
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:net.sourceforge.processdash.ui.web.reports.RadarChart.java

/** Create a radar chart. */
@Override//from  ww  w . j a  v  a2 s  . c o m
public JFreeChart createChart() {
    maybeScaleDataAxes();
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getRowCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);

    RadarPlot plot = new RadarPlot(pieData);
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    if (parameters.get("skipAxisLabels") != null)
        plot.setShowAxisLabels(false);
    String interiorGap = getParameter("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = getParameter("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }

    return chart;
}

From source file:org.mwc.cmap.grideditor.chart.ChartBuilder.java

public JFreeChart buildChart() {
    final ValueAxis xAxis = myManager.createXAxis();
    final ValueAxis yAxis = myManager.createYAxis();
    final XYDataset data = myManager.getXYDataSet();
    final XYLineAndShapeRenderer renderer = new ColorRenderer();
    final XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    final JFreeChart result = new JFreeChart(myManager.getChartTitle(), JFreeChart.DEFAULT_TITLE_FONT, xyplot,
            false);//from w  w  w.ja  va  2s  .  c  om
    ChartUtilities.applyCurrentTheme(result);
    return result;
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithBoxAndWhiskerChart.java

protected void init() {
    dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);//from w  ww.  j a v  a 2  s .  c o m
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart(getName(), new Font("SansSerif", Font.BOLD, 14), plot, true);

    init(chart.getPlot());
}

From source file:bzstats.chart.KillRatioHistoryChart.java

protected JFreeChart getChart() {

    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    fillDataset(dataset);/*from   w w w  .  jav a2 s .  c o  m*/

    XYPlot plot = new XYPlot();

    NumberAxis xaxis = new NumberAxis("Time");
    xaxis.setTickLabelsVisible(false);
    NumberAxis yaxis = new NumberAxis("Killratio");

    plot.setDomainAxis(xaxis);
    plot.setRangeAxis(yaxis);
    plot.setDataset(dataset);
    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES));

    JFreeChart chart = new JFreeChart("Killratio", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.addSubtitle(new TextTitle("kills/deaths"));

    chart.setBackgroundPaint(Color.white);

    return chart;

}

From source file:aka.pirana.jdoc.JChart.java

private JPanel createChartPanel() {
    NumberAxis numberaxis = new NumberAxis("Date");
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("%");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    XYPlot xyplot = new XYPlot(SampleGenerator(), numberaxis, numberaxis1, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("JDocSplineRenderer", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    return chartpanel;
}