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:org.jfree.chart.demo.MemoryUsageDemo.java

public MemoryUsageDemo(int i) {
    super(new BorderLayout());
    total = new TimeSeries("Total Memory");
    total.setMaximumItemAge(i);//from  ww w .  j a v  a  2 s  . c o  m
    free = new TimeSeries("Free Memory");
    free.setMaximumItemAge(i);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(total);
    timeseriescollection.addSeries(free);
    DateAxis dateaxis = new DateAxis("Time");
    NumberAxis numberaxis = new NumberAxis("Memory");
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.red);
    xylineandshaperenderer.setSeriesPaint(1, Color.green);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    dateaxis.setAutoRange(true);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true);
    jfreechart.setBackgroundPaint(Color.white);
    ChartPanel chartpanel = new ChartPanel(jfreechart, true);
    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    add(chartpanel);
}

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

/**
 * Creates the MeterChart .//from  w  w  w .  ja va  2s  . c  o m
 * 
 * @return A MeterChart .
 */
public JFreeChart createChart() {
    logger.debug("IN");
    if (dataset == null) {
        logger.debug("The dataset to be represented is null");
        return null;
    }
    MeterPlot plot = new MeterPlot((ValueDataset) dataset);
    logger.debug("Created new plot");
    plot.setRange(new Range(lower, upper));
    logger.debug("Setted plot range");

    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval interval = (KpiInterval) iterator.next();
        plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()),
                Color.lightGray, new BasicStroke(2.0f), interval.getColor()));
        logger.debug("Added new interval to the plot");
    }

    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.CHORD);
    plot.setMeterAngle(260);
    plot.setTickLabelsVisible(true);
    Font f = new Font("Arial", Font.PLAIN, 11);
    plot.setTickLabelFont(f);
    plot.setTickLabelPaint(Color.darkGray);
    plot.setTickSize(5.0);
    plot.setTickPaint(Color.lightGray);
    plot.setValuePaint(Color.black);
    plot.setValueFont(new Font("Arial", Font.PLAIN, 14));
    logger.debug("Setted all properties of the plot");

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    logger.debug("Created the chart");
    chart.setBackgroundPaint(color);
    logger.debug("Setted 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");
    }
    logger.debug("OUT");
    return chart;
}

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

/**
 * Displays a meter chart.//from ww  w. j a va 2s .  c  om
 *
 * @param value  the value.
 * @param shape  the dial shape.
 */
void displayMeterChart(final double value, final DialShape shape) {

    final DefaultValueDataset data = new DefaultValueDataset(75.0);
    final MeterPlot plot = new MeterPlot(data);
    plot.setUnits("Degrees");
    plot.setRange(new Range(20.0, 140.0));
    //        plot.setNormalRange(new Range(70.0, 100.0));
    //      plot.setWarningRange(new Range(100.0, 120.0));
    //    plot.setCriticalRange(new Range(120.0, 140.0));

    plot.setDialShape(shape);
    plot.setNeedlePaint(Color.white);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 9));

    //  plot.setInsets(new Insets(5, 5, 5, 5));
    final JFreeChart chart = new JFreeChart("Meter Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    //        final MeterLegend legend = new MeterLegend("Sample Meter");
    //      chart.setLegend(legend);

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    final JFrame chartFrame = new ChartFrame("Meter Chart", chart);
    chartFrame.addWindowListener(new WindowAdapter() {
        /**
         * Invoked when a window is in the process of being closed.
         * The close operation can be overridden at this point.
         */
        public void windowClosing(final WindowEvent e) {
            System.exit(0);
        }
    });
    chartFrame.pack();
    RefineryUtilities.positionFrameRandomly(chartFrame);
    chartFrame.setSize(250, 250);
    chartFrame.setVisible(true);

}

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

/**
 * Creates a new demo instance.//from www . j a  v a2 s.  co  m
 *
 * @param title  the frame title.
 */
public LayeredBarChartDemo2(final String title) {

    super(title);

    // create a dataset...
    final double[][] data = new double[][] { { 41.0, 33.0, 22.0, 64.0, 42.0, 62.0, 22.0, 14.0 },
            { 55.0, 63.0, 55.0, 48.0, 54.0, 37.0, 41.0, 39.0 },
            { 57.0, 75.0, 43.0, 33.0, 63.0, 46.0, 57.0, 33.0 } };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);

    // create the chart...
    final CategoryAxis categoryAxis = new CategoryAxis("Category");
    final ValueAxis valueAxis = new NumberAxis("Score (%)");

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new LayeredBarRenderer());

    plot.setOrientation(PlotOrientation.VERTICAL);
    final JFreeChart chart = new JFreeChart("Layered Bar Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.lightGray);

    final LayeredBarRenderer renderer = (LayeredBarRenderer) plot.getRenderer();

    // we can set each series bar width individually or let the renderer manage a standard view.
    // the width is set in percentage, where 1.0 is the maximum (100%).
    renderer.setSeriesBarWidth(0, 1.0);
    renderer.setSeriesBarWidth(1, 0.7);
    renderer.setSeriesBarWidth(2, 0.5);

    renderer.setItemMargin(0.01);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(0.25);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.SimpleScatterPlot.java

public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel, String yLabel) {
    super(null, true);

    setBackground(Color.white);//from www .  j  a  v a 2s .  com
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    xAxis = new NumberAxis(xLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);

    yAxis = new NumberAxis(yLabel);
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    xyDataset = new DefaultXYZDataset();
    int length = Math.min(xValues.length, yValues.length);
    double[][] data = new double[3][length];
    System.arraycopy(xValues, 0, data[0], 0, length);
    System.arraycopy(yValues, 0, data[1], 0, length);
    System.arraycopy(colors, 0, data[2], 0, length);
    xyDataset.addSeries(SERIES_ID, data);

    XYDotRenderer renderer = new XYDotRenderer() {
        @Override
        public Paint getItemPaint(int row, int col) {
            double c = xyDataset.getZ(row, col).doubleValue();
            return Color.getHSBColor((float) c, 1.0f, 1.0f);
        }
    };

    renderer.setDotHeight(3);
    renderer.setDotWidth(3);

    plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false);
    chart.setBackgroundPaint(Color.white);

    super.setChart(chart);
}

From source file:net.sf.profiler4j.console.AllocDiffPanel.java

public AllocDiffPanel(int maxAgeMillis) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAgeMillis);

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);

    NumberAxis numberAxis = new NumberAxis("Allocs/Sec");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);//from  ww  w . j a  v  a 2 s .  c o m
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM",
            new Font("SansSerif", Font.PLAIN, 18), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:ec.ui.chart.ChartPopup.java

private JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    JFreeChart result = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, false);
    return result;
}

From source file:br.prof.salesfilho.oci.image.GraphicBuilder.java

public void createCombinedChart(Map<String, double[]> mapSeries, String legendTitle) {
    XYSeriesCollection xds;//from   w w  w . j a va  2  s  . c om
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis(legendTitle));
    plot.setGap(10.0);
    for (Map.Entry<String, double[]> entrySet : mapSeries.entrySet()) {
        String serieName = entrySet.getKey();
        double[] values = entrySet.getValue();

        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

        final XYSeries series = new XYSeries(serieName);
        for (int i = 0; i < values.length; i++) {
            series.add(i, Precision.round(values[i], 2));
            renderer.setSeriesVisible(i, true, true);
            renderer.setSeriesShapesVisible(i, true);
        }
        xds = new XYSeriesCollection();
        xds.addSeries(series);

        final NumberAxis rangeAxis = new NumberAxis(serieName);

        final XYPlot subplot = new XYPlot(xds, null, rangeAxis, renderer);
        subplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        plot.add(subplot);

    }
    this.chart = new JFreeChart(this.title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chartPanel.setChart(chart);
}

From source file:playground.yu.utils.charts.XYScatterLineChart.java

private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel,
        final XYSeriesCollection dataset) {
    // return ChartFactory.createScatterPlot(title, categoryAxisLabel,
    // valueAxisLabel, dataset, PlotOrientation.VERTICAL, true, // legend?
    // false, // tooltips?
    // false // URLs?
    // );/*  w  w w. j  a  v a 2  s .co  m*/
    NumberAxis xAxis = new NumberAxis(categoryAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(0, 24);
    NumberAxis yAxis = new NumberAxis(valueAxisLabel);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setRange(0, 100);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, true);
    renderer.setBaseToolTipGenerator(null/* XYToolTipGenerator */);
    renderer.setURLGenerator(null/* urlGenerator */);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true/* legend */);
    return chart;
}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates a chart containing multiple pie charts, from a TableDataset.
 *
 * @param title  the chart title./*from w w w  .  ja  v  a  2 s  .  co m*/
 * @param data  the dataset for the chart.
 * @param extractType  <code>PER_ROW</code> or <code>PER_COLUMN</code> (defined in 
 *                     {@link PiePlot}).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return a pie chart.
 */
public static JFreeChart createPieChart(String title, java.awt.Font titleFont, CategoryDataset data,
        TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) {

    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    //pp.setInsets(new Insets(0, 5, 5, 5));
    pp.setBackgroundPaint(null);
    // no outline around each piechart
    pp.setOutlineStroke(null);
    //plot.setOutlineStroke(null);
    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = new StandardPieToolTipGenerator();
    }

    //PieURLGenerator urlGenerator = null;
    if (!urls) {
        urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}