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, Plot plot) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

From source file:scatterplot1k.JFreeScatter.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title      the frame title.//from  ww w. j  a  v a  2s. com
 * @param sampleSize
 */
public JFreeScatter(final String title, int sampleSize) {
    super(title);
    this.sampleCount = sampleSize;

    data = new float[2][sampleSize];
    populateData();
    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    //        chart.setLegend(null);

    // force aliasing of the rendered content..
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(800, 600));
    //      panel.setHorizontalZoom(true);
    //    panel.setVerticalZoom(true);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);

}

From source file:biz.ixnay.pivot.charts.skin.jfree.SingleValueChartSkin.java

protected JFreeChart createChart(Plot plot) {
    if (plot == null) {
        throw new IllegalArgumentException("plot cannot be null.");
    }/*ww  w. ja  v a  2  s.  c  o m*/

    SingleValueChartView chartView = (SingleValueChartView) getComponent();

    String title = chartView.getTitle();

    JFreeChart chart = new JFreeChart(title, plot);

    // TODO: anything else that we need to set before returning?

    return chart;
}

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

public TimePeriodValuesDemo1(String s) {
    super(s);/*from  ww  w. ja  va2  s. c  o  m*/
    XYDataset xydataset = createDataset1();
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setVerticalTickLabels(true);
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Value");
    XYPlot xyplot = new XYPlot(xydataset, dateaxis, numberaxis, xybarrenderer);
    XYDataset xydataset1 = createDataset2();
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3);
    standardxyitemrenderer.setBaseShapesFilled(true);
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, standardxyitemrenderer);
    JFreeChart jfreechart = new JFreeChart("Supply and Demand", xyplot);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}

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

private static JFreeChart createChart(MultiValueCategoryDataset multivaluecategorydataset) {
    CategoryPlot categoryplot = new CategoryPlot(multivaluecategorydataset, new CategoryAxis("Category"),
            new NumberAxis("Value"), new ScatterRenderer());
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("ScatterRendererDemo1", categoryplot);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:org.neo4j.bench.chart.JFreeStackedBarChart.java

public JFreeChart render(String title, CategoryPlot plot, AbstractRenderer renderer) {
    plot.getDomainAxis()//from  w w w  .  jav  a2s.  c  o m
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
    return new JFreeChart(title, plot);
}

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

private static JFreeChart createChart() {
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Date/Time"));
    combineddomainxyplot.setDomainPannable(true);
    combineddomainxyplot.add(createSubplot1(createDataset1()));
    combineddomainxyplot.add(createSubplot2(createDataset2()));
    JFreeChart jfreechart = new JFreeChart("XYTaskDatasetDemo2", combineddomainxyplot);
    jfreechart.setBackgroundPaint(Color.white);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartTemplate.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    plot.setDataset(0, this.getDataset());
    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.setTextAntiAlias(true);//  w  w  w.  j  a va2 s  .c o  m
    //    chart.removeLegend();
    return chart;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);//from   w  w w. j  a v a2 s  .  c  o m
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:org.openimaj.demos.sandbox.flickr.geo.PlotFlickrGeo.java

public static void main(String[] args) throws IOException {
    final File inputcsv = new File("/Volumes/SSD/training_latlng");
    final List<double[]> data = new ArrayList<double[]>(10000000);

    // read in images
    final BufferedReader br = new BufferedReader(new FileReader(inputcsv));
    String line;//from   w  ww  .j  a  v  a  2 s .  co m
    int i = 0;
    br.readLine();
    while ((line = br.readLine()) != null) {
        final String[] parts = line.split(" ");

        final double longitude = Double.parseDouble(parts[2]);
        final double latitude = Double.parseDouble(parts[1]);

        data.add(new double[] { longitude, latitude });

        if (longitude >= -0.1 && longitude < 0 && latitude > 50 && latitude < 54)
            System.out.println(parts[0] + " " + latitude + " " + longitude);

        // if (i++ % 10000 == 0)
        // System.out.println(i);
    }
    br.close();

    System.out.println("Done reading");

    final float[][] dataArr = new float[2][data.size()];
    for (i = 0; i < data.size(); i++) {
        dataArr[0][i] = (float) data.get(i)[0];
        dataArr[1][i] = (float) data.get(i)[1];
    }

    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setRange(-180, 180);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setRange(-90, 90);
    final FastScatterPlot plot = new FastScatterPlot(dataArr, domainAxis, rangeAxis);

    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    final ApplicationFrame frame = new ApplicationFrame("Title");
    frame.setContentPane(chartPanel);
    frame.pack();
    frame.setVisible(true);
}

From source file:org.spf4j.perf.impl.chart.Charts.java

public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values,
        final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
    final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis,
            stepMillis);//from   ww w.  j  av a2  s  .com
    NumberAxis xAxis = new NumberAxis("Time");
    xAxis.setStandardTickUnits(dataSet.createXTickUnits());
    xAxis.setLowerMargin(0);
    xAxis.setUpperMargin(0);
    xAxis.setVerticalTickLabels(true);
    NumberAxis yAxis = new NumberAxis(uom);
    yAxis.setStandardTickUnits(dataSet.createYTickUnits());
    yAxis.setLowerMargin(0);
    yAxis.setUpperMargin(0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    PaintScale scale;
    if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
        if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
            scale = new InverseGrayScale(0, 1);
        } else {
            scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
        }
    } else {
        scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
    }
    renderer.setPaintScale(scale);
    renderer.setBlockWidth(1);
    renderer.setBlockHeight(1);
    XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);
    JFreeChart chart = new JFreeChart(chartName, plot);
    PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
    legend.setMargin(0, 5, 0, 5);
    chart.addSubtitle(legend);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    return chart;
}