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

private static JFreeChart createChart(CategoryDataset categorydataset, CategoryDataset categorydataset1) {
    CategoryAxis categoryaxis = new CategoryAxis("Category");
    NumberAxis numberaxis = new NumberAxis("Value");
    GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer();
    KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1");
    keytogroupmap.mapKeyToGroup("Series 1A", "G1");
    keytogroupmap.mapKeyToGroup("Series 1B", "G1");
    keytogroupmap.mapKeyToGroup("NOTHING", "G2");
    groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap);
    CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis,
            groupedstackedbarrenderer) {

        private static final long serialVersionUID = 1L;

        public LegendItemCollection getLegendItems() {
            LegendItemCollection legenditemcollection = new LegendItemCollection();
            legenditemcollection.addAll(getRenderer().getLegendItems());
            CategoryDataset categorydataset2 = getDataset(1);
            if (categorydataset2 != null) {
                CategoryItemRenderer categoryitemrenderer = getRenderer(1);
                if (categoryitemrenderer != null) {
                    org.jfree.chart.LegendItem legenditem = categoryitemrenderer.getLegendItem(1, 1);
                    legenditemcollection.add(legenditem);
                }//from w  ww .ja v  a  2s . co  m
            }
            return legenditemcollection;
        }

    };
    JFreeChart jfreechart = new JFreeChart("Dual Axis Bar Chart", categoryplot);
    categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    categoryplot.setDataset(1, categorydataset1);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    categoryplot.setRangeAxis(1, numberaxis1);
    categoryplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    BarRenderer barrenderer = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:lk.ac.mrt.projectx.buildex.complex.FormalVerifier.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title the frame title.//w  w w.j  a va 2  s. co  m
 */
public FormalVerifier(final String title, final String lblx, final String lbly) throws IOException {

    super(title);
    populateData();
    final NumberAxis domainAxis = new NumberAxis(lblx);
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis(lbly);
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart(title, 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(3000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(3000);

    setContentPane(panel);
    //TODO : Print

    ChartUtilities.saveChartAsJPEG(
            new File("F:\\FYP2\\FinalP\\graphs\\Twirl" + System.currentTimeMillis() + ".jpg"), chart, 800, 600);

}

From source file:pwm.visualizer.MDPPolicyPanel.java

private JFreeChart createChart() {
    NumberAxis nutritionAxis = new NumberAxis("Calories/Day");
    nutritionAxis.setLowerBound(0);/* w ww .  ja  va2  s.  c  o m*/
    nutritionAxis.setUpperBound(5000);
    nutritionAxis.setAutoRange(false);
    //      
    CategoryPlot categoryplot = new CategoryPlot(nutritionDataSet, new CategoryAxis("Weight(KG)"),
            nutritionAxis, new BarRenderer());
    CategoryAxis xaxis = categoryplot.getDomainAxis();
    xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

    LegendItemCollection legend = new LegendItemCollection();
    LegendItem nutritionLegend = new LegendItem("Calories/Day");
    LegendItem exerciseLegend = new LegendItem("Physical Activity Level");
    nutritionLegend.setFillPaint(Color.BLUE);
    exerciseLegend.setFillPaint(Color.RED);

    legend.add(nutritionLegend);
    legend.add(exerciseLegend);

    categoryplot.setFixedLegendItems(legend);
    JFreeChart jfreechart = new JFreeChart("Policy Visualizer", categoryplot);
    categoryplot.setDataset(1, exerciseDataSet);
    categoryplot.mapDatasetToRangeAxis(1, 1);

    NumberAxis exerciseAxis = new NumberAxis("Physical Activity Level");
    exerciseAxis.setLowerBound(0);
    exerciseAxis.setUpperBound(3.0);
    exerciseAxis.setAutoRange(false);

    categoryplot.setRangeAxis(1, exerciseAxis);
    BarRenderer barrenderer1 = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer1);

    //        BarRenderer stackedbarrenderer = (BarRenderer)categoryplot.getRenderer();
    //        stackedbarrenderer.setDrawBarOutline(true);
    //        stackedbarrenderer.setBaseItemLabelsVisible(false);
    //        stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    ChartUtilities.applyCurrentTheme(jfreechart);

    return jfreechart;

}

From source file:playground.dgrether.analysis.charts.DgMixedDeltaUtilsModeGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);//from ww w  . ja v a 2 s.  co m
    plot.setRangeAxis(yAxis);
    //RANGE
    xAxis.setRange(0.0, 102.0);
    yAxis.setRange(-0.31, 0.61);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true);
    renderer1.setSeriesPaint(0, colorScheme.COLOR1B);
    renderer1.setSeriesPaint(1, colorScheme.COLOR2B);
    renderer1.setSeriesPaint(2, colorScheme.COLOR3B);
    renderer1.setSeriesPaint(3, colorScheme.COLOR4B);
    plot.setDataset(0, this.inomeModeChoiceDs);
    plot.setRenderer(0, renderer1);

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(1, this.avgDeltaScoreIncomeDs);
    for (int i = 0; i <= 3; i++) {
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(1, renderer2);
    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

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

/**
 * A demonstration application showing how to....
 *
 * @param title  the frame title.//from  w  w  w. ja v  a  2 s  .  c o  m
 */
public TimePeriodValuesDemo(final String title) {

    super(title);

    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer();

    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1));
    domainAxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);
    final ValueAxis rangeAxis = new NumberAxis("Value");

    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);

    final XYDataset data2 = createDataset2();
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(
            StandardXYItemRenderer.SHAPES_AND_LINES);
    renderer2.setShapesFilled(true);

    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);

    final JFreeChart chart = new JFreeChart("Supply and Demand", plot);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);

}

From source file:net.pickapack.chart.LinePlotFrame.java

/**
 * Create a line plot frame./* w  ww.  ja  v  a 2  s  .c  o m*/
 *
 * @param linePlot the line plot
 * @param width the width
 * @param height the height
 */
public LinePlotFrame(LinePlot linePlot, int width, int height) {
    super(linePlot.getTitle());
    this.linePlot = linePlot;

    this.numSubPlots = linePlot.getSubLinePlots().size();

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.dataSets = new ArrayList<TimeSeriesCollection>();
    this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>();

    for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) {
        TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection();
        this.dataSets.add(dataSetsPerSubPlot);

        HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>();
        this.dataSinks.add(dataSinksPerSubPlot);

        for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) {
            TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle());
            dataSetsPerSubPlot.addSeries(timeSeries);
            dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback());
        }

        NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY());
        rangeAxis.setAutoRangeIncludesZero(false);
        XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(3600000.0);

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

    DataSink dataSink = new DataSink();
    new Thread(dataSink).start();
}

From source file:org.esa.beam.smos.visat.GridPointBtDataFlagmatrixToolView.java

@Override
protected JComponent createGridPointComponent() {
    dataset = new DefaultXYZDataset();

    final NumberAxis xAxis = new NumberAxis("Record #");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);/*from ww w.  j  a  v a 2 s .  c  om*/
    xAxis.setUpperMargin(0.0);

    flagNames = createFlagNames(Dddb.getInstance().getFlagDescriptors(DEFAULT_FLAG_DESCRIPTOR_IDENTIFIER));
    final NumberAxis yAxis = createRangeAxis(flagNames);

    final LookupPaintScale paintScale = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    paintScale.add(0.0, Color.BLACK);
    paintScale.add(1.0, Color.RED);
    paintScale.add(2.0, Color.GREEN);
    paintScale.add(3.0, Color.BLUE);
    paintScale.add(4.0, Color.YELLOW);

    final XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    renderer.setBaseToolTipGenerator(new FlagToolTipGenerator(flagNames));

    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setForegroundAlpha(0.5f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage("No data");

    chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:arduinoserialread.SerialRead.java

private void initGUI() {

    // init the frame
    frame.setTitle("Arduino Serial Read");
    frame.setBounds(100, 100, 600, 500);
    frame.setMinimumSize(new Dimension(600, 500));
    frame.setLocationRelativeTo(null);// ww  w.  j a  v a  2s  . c  o m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // init control panel
    JPanel ctrlPanel = new JPanel();
    ctrlPanel.setLayout(new FlowLayout());

    // init the serial connection panel
    serialCOM = new SerialConnectionPanel();
    ctrlPanel.add(serialCOM);
    frame.getContentPane().add(ctrlPanel, BorderLayout.SOUTH);

    // init the connection status
    ConnectionStatus connectionStatus = new ConnectionStatus();
    ctrlPanel.add(connectionStatus);

    // init connect and disconnect button
    connect = new JButton("connect");
    ctrlPanel.add(connect);
    disconnect = new JButton("disconnect");
    ctrlPanel.add(disconnect);

    // init real time chart
    TimeSeries series = new TimeSeries("DATA");
    DateAxis timeAxis = new DateAxis("Time");
    dataset = new TimeSeriesCollection(series);
    NumberAxis rangeAxis = new NumberAxis("Data");
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(true);
    XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis, new StandardXYItemRenderer());
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.getRenderer().setSeriesPaint(0, new Color(0, 142, 192));
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setAutoRange(true);
    domainAxis.setFixedAutoRange(30000.0); // 30 seconds
    // init the JFreeChart
    JFreeChart chart = new JFreeChart("Real-Time Data Chart", plot);
    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();
    // add real time chart to the frame
    ChartPanel chartPanel = new ChartPanel(chart);
    frame.getContentPane().add(chartPanel, BorderLayout.CENTER);

}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//from  ww  w  . ja va2  s.c  o  m
 */
public DynamicDataDemo3(final String title) {

    super(title);

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        this.lastValue[i] = 100.0;
        final TimeSeries series = new TimeSeries("Random " + i, Millisecond.class);
        this.datasets[i] = new TimeSeriesCollection(series);
        final NumberAxis rangeAxis = new NumberAxis("Y" + i);
        rangeAxis.setAutoRangeIncludesZero(false);
        final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    final JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);
    //        chart.getLegend().setAnchor(Legend.EAST);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        final JButton button = new JButton("Series " + i);
        button.setActionCommand("ADD_DATA_" + i);
        button.addActionListener(this);
        buttonPanel.add(button);
    }
    final JButton buttonAll = new JButton("ALL");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

}

From source file:edu.ucla.stat.SOCR.chart.demo.CategoryStepChartDemo1.java

/**
 * Creates a chart.//from www .  j  av a  2 s .  c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    CategoryItemRenderer renderer = new CategoryStepRenderer(true);

    CategoryAxis domainAxis = new CategoryAxis(domainLabel);
    NumberAxis rangeAxis = new NumberAxis(rangeLabel);
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart(chartTitle, plot);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    AbstractCategoryItemRenderer renderer2 = (AbstractCategoryItemRenderer) plot.getRenderer();
    renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    setCategorySummary(dataset);
    if (legendPanelOn)
        chart.removeLegend();
    return chart;

}