Example usage for org.jfree.chart.plot XYPlot XYPlot

List of usage examples for org.jfree.chart.plot XYPlot XYPlot

Introduction

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

Prototype

public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) 

Source Link

Document

Creates a new plot with the specified dataset, axes and renderer.

Usage

From source file:ascensionxyplot.AscensionXYPlot.java

/**
 * Creates a combined chart./* ww  w .j a  v  a  2  s .c  om*/
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart(File dataFile) {

    // create subplot 1...
    final XYDataset data1 = createDataset1(dataFile);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // add secondary axis
    //        subplot1.setDataset(1, createDataset2());
    //        final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    //        axis2.setAutoRangeIncludesZero(false);
    //        subplot1.setRangeAxis(1, axis2);
    //        subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    //        subplot1.setRenderer(1, new StandardXYItemRenderer());       
    //        subplot1.mapDatasetToRangeAxis(1, 1);

    final XYTextAnnotation annotation1 = new XYTextAnnotation("x value", 20.0, 120000.0);
    final XYTextAnnotation annotation2 = new XYTextAnnotation("y value", 20.0, 110000.0);
    final XYTextAnnotation annotation3 = new XYTextAnnotation("z value", 20.0, 100000.0);
    final XYTextAnnotation annotation4 = new XYTextAnnotation("timepoint", 20.0, 10000.0);
    annotation1.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation2.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation3.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation4.setFont(new Font("SansSerif", Font.PLAIN, 9));
    //        annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation1);
    subplot1.addAnnotation(annotation2);
    subplot1.addAnnotation(annotation3);
    subplot1.addAnnotation(annotation4);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Is this the title?", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:tl.lib.dataCollection.gui.TimeSeriesChart.java

public TimeSeriesChart(_CollectionGUIScenario scenario, String label, String description, String labelAxisY) {
    super(null);//  w w w .jav  a 2s.  c  om
    this.sourceDescriptor = scenario.getSourceDescriptor();
    this.collection = new XYSeriesCollection();

    // ChartTheme currentTheme = new StandardChartTheme("JFree");
    ValueAxis timeAxis = new DateAxis("Time");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(labelAxisY);
    valueAxis.setAutoRangeIncludesZero(false); // override default

    XYToolTipGenerator toolTipGenerator = null;
    toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    // XYURLGenerator urlGenerator = new StandardXYURLGenerator();
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    // renderer.setURLGenerator(urlGenerator);

    this.plot = new XYPlot(collection, timeAxis, valueAxis, renderer);

    this.chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    // currentTheme.apply(chart);

    renderingInfo = new ChartRenderingInfo();

    this.scenario = scenario;
    this.description = description;
    this.label = label;
    this.selected = new Vector<SourceId>();
    default_all = true;
    super.setChart(chart);
}

From source file:genj.chart.Chart.java

/**
 * Constructor for a chart with indexed series of data, shown on a 2d pane
 * as one plot per series or one horizontal stripe per series (stacked).
 * @param title the title of the chart//  w ww. j  a  v  a  2 s  . c o  m
 * @param labelAxisX a label for the x-axis
 * @param labelAxisY a label for the y-axis
 * @param series one or more indexed series to show
 * @param stacked whether to stack horizontal stripes one for each series instead of showing one plot per series
 */
public Chart(String title, String labelAxisX, String labelAxisY, IndexedSeries[] series, NumberFormat format,
        boolean stacked) {

    // prepare chart setup
    NumberAxis xAxis = new NumberAxis(labelAxisX);
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis(labelAxisY);
    yAxis.setNumberFormatOverride(format);

    XYItemRenderer renderer = stacked ? new StackedXYAreaRenderer2() : new XYAreaRenderer();
    XYPlot plot = new XYPlot(IndexedSeries.asTableXYDataset(series), xAxis, yAxis, renderer);

    // init
    init(title, plot, true);

    // done
}

From source file:tl.lib.dataCollection.gui.NumXYChart.java

public NumXYChart(_CollectionGUIScenario scenario, String label, String description, String labelAxisY) {
    super(null);/*  w  ww  .  ja va 2  s .c o  m*/
    this.sourceDescriptor = scenario.getSourceDescriptor();
    this.collection = new XYSeriesCollection();

    // ChartTheme currentTheme = new StandardChartTheme("JFree");
    NumberAxis valueAxisX = new NumberAxis("Sample Number");
    valueAxisX.setAutoRangeIncludesZero(false); // override default
    NumberAxis valueAxisY = new NumberAxis(labelAxisY);
    valueAxisY.setAutoRangeIncludesZero(false); // override default

    XYToolTipGenerator toolTipGenerator = null;
    toolTipGenerator = new StandardXYToolTipGenerator();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    // XYURLGenerator urlGenerator = new StandardXYURLGenerator();
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    // renderer.setURLGenerator(urlGenerator);

    this.plot = new XYPlot(collection, valueAxisX, valueAxisY, renderer);

    this.chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    // currentTheme.apply(chart);

    renderingInfo = new ChartRenderingInfo();

    this.scenario = scenario;
    this.description = description;
    this.label = label;
    this.selected = new Vector<SourceId>();
    default_all = true;
    super.setChart(chart);
}

From source file:org.perfmon4j.visualvm.chart.DynamicTimeSeriesChart.java

public DynamicTimeSeriesChart(int maxAgeInSeconds) {
    super(new BorderLayout());
    this.maxAgeInSeconds = maxAgeInSeconds;

    dataset = new TimeSeriesCollection();
    renderer = new MyXYRenderer();
    renderer.setBaseStroke(NORMAL_STROKE);

    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setAutoRange(false);/*from   w  w w  .j  a va2 s  .  c  o m*/
    numberAxis.setRange(new Range(0d, 100d));

    DateAxis dateAxis = new DateAxis();
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    dateAxis.setAutoRange(true);
    dateAxis.setFixedAutoRange(maxAgeInSeconds * 1000);
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 30));

    XYPlot plot = new XYPlot(dataset, dateAxis, numberAxis, renderer);
    JFreeChart chart = new JFreeChart(null, null, plot, false);
    chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    chartPanel.setPopupMenu(null);

    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1),
            BorderFactory.createLineBorder(Color.black)));

    add(chartPanel);
}

From source file:ch.epfl.leb.sass.ijplugin.SimulatorStatusFrame.java

/** 
 * Creates a new status frame./*from   w w w. j a v  a  2 s  .  co m*/
 * 
 * @param groundTruthYLabel The y-axis label for the ground truth signal.
 * @param analyzerYLabel The units output by the analyzer.
 * @param setpointYLabel The units of the controller setpoint.
 * @param outputYLabel The units output by the controller.
 */
public SimulatorStatusFrame(String groundTruthYLabel, String analyzerYLabel, String setpointYLabel,
        String outputYLabel) {
    String seriesLabel = "";
    String yLabel = "";
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new NumberAxis("Simulation Outputs"));
    Font yLabelFont = new Font("Dialog", Font.PLAIN, 10);
    datasets = new XYSeriesCollection[4];
    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        switch (i) {
        case 0:
            seriesLabel = "True density";
            yLabel = groundTruthYLabel;
            break;
        case 1:
            seriesLabel = "Analyzer output";
            yLabel = analyzerYLabel;
            break;
        case 2:
            seriesLabel = "Setpoint";
            yLabel = setpointYLabel;
            break;
        case 3:
            seriesLabel = "Controller output";
            yLabel = outputYLabel;
            break;
        }

        XYSeries timeseries = new XYSeries(seriesLabel);
        datasets[i] = new XYSeriesCollection(timeseries);

        NumberAxis numberaxis = new NumberAxis(yLabel);
        numberaxis.setAutoRangeIncludesZero(false);
        numberaxis.setNumberFormatOverride(new DecimalFormat("###0.00"));
        XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer());
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        xyplot.getRangeAxis().setLabelFont(yLabelFont);
        combineddomainxyplot.add(xyplot);
    }

    JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, true);
    jfreechart.setBorderPaint(Color.black);
    jfreechart.setBorderVisible(true);
    jfreechart.setBackgroundPaint(Color.white);
    combineddomainxyplot.setBackgroundPaint(Color.lightGray);
    combineddomainxyplot.setDomainGridlinePaint(Color.white);
    combineddomainxyplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    // Number of frames to display
    valueaxis.setFixedAutoRange(2000D);

    ChartPanel chartpanel = new ChartPanel(jfreechart);

    chartpanel.setPreferredSize(new Dimension(800, 500));
    chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    chartpanel.setVisible(true);

    JPanel jPanel = new JPanel();
    jPanel.setLayout(new BorderLayout());
    jPanel.add(chartpanel, BorderLayout.NORTH);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    add(jPanel);
    pack();
    setVisible(true);

}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesUnkownFailuresChart.java

@Override
protected JFreeChart createGraph() {
    TimeTableXYDataset dataset = createDataset();

    ValueAxis xAxis = new DateAxis();
    xAxis.setLowerMargin(0.0);// w w  w  .  ja va 2 s  . c  o  m
    xAxis.setUpperMargin(0.0);

    Calendar lowerBound = getLowerGraphBound();
    xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis());

    NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL);
    yAxis.setRange(0, HUNDRED_PERCENT);

    XYItemRenderer renderer = new XYBarRenderer();

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

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

    return chart;
}

From source file:com.yahoo.egads.utilities.GUIUtils.java

/**
 * Creates a combined chart./*from  w w  w.j ava  2s  .  c  o m*/
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart(DataSequence tsOne, DataSequence tsTwo, ArrayList<Anomaly> anomalyList) {

    // create subplot 1.
    final XYDataset data1 = createDataset(tsOne, "Original");
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Original Value");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // plot anomalies on subplot 1.
    addAnomalies(subplot1, anomalyList);

    // create subplot 2.
    final XYDataset data2 = createDataset(tsTwo, "Forecast");
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Forecast Value");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot.
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time"));
    plot.setGap(10.0);

    // add the subplots.
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);

    // Add anomaly score time-series.
    addAnomalyTS(plot, tsOne, tsTwo);

    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot.
    return new JFreeChart("EGADS GUI", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:org.btrg.df.betterologist.swingui.ProjectJobSchedulingPanel.java

private JFreeChart createChart(Schedule schedule) {
    YIntervalSeriesCollection seriesCollection = new YIntervalSeriesCollection();
    Map<Project, YIntervalSeries> projectSeriesMap = new LinkedHashMap<Project, YIntervalSeries>(
            schedule.getProjectList().size());
    YIntervalRenderer renderer = new YIntervalRenderer();
    int maximumEndDate = 0;
    int seriesIndex = 0;
    for (Project project : schedule.getProjectList()) {
        YIntervalSeries projectSeries = new YIntervalSeries(project.getLabel());
        seriesCollection.addSeries(projectSeries);
        projectSeriesMap.put(project, projectSeries);
        renderer.setSeriesShape(seriesIndex, new Rectangle());
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        seriesIndex++;/*from w  w  w  . ja v a 2 s  .c  o m*/
    }
    for (Allocation allocation : schedule.getAllocationList()) {
        int startDate = allocation.getStartDate();
        int endDate = allocation.getEndDate();
        YIntervalSeries projectSeries = projectSeriesMap.get(allocation.getProject());
        projectSeries.add(allocation.getId(), (startDate + endDate) / 2.0, startDate, endDate);
        maximumEndDate = Math.max(maximumEndDate, endDate);
    }
    NumberAxis domainAxis = new NumberAxis("Job");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, schedule.getAllocationList().size() - 0.5);
    domainAxis.setInverted(true);
    NumberAxis rangeAxis = new NumberAxis("Day (start to end date)");
    rangeAxis.setRange(-0.5, maximumEndDate + 0.5);
    XYPlot plot = new XYPlot(seriesCollection, domainAxis, rangeAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    return new JFreeChart("Project Job Scheduling", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//  w ww . java  2s . com
 */
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);

}