Example usage for org.jfree.data.time TimeSeriesCollection addSeries

List of usage examples for org.jfree.data.time TimeSeriesCollection addSeries

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeriesCollection addSeries.

Prototype

public void addSeries(TimeSeries series) 

Source Link

Document

Adds a series to the collection and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

/**
 * Some tests for the indexOf() method./*from w w  w . j  a v  a2  s.c  o m*/
 */
@Test
public void testIndexOf() {
    TimeSeries s1 = new TimeSeries("S1");
    TimeSeries s2 = new TimeSeries("S2");
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));

    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));

    TimeSeries s2b = new TimeSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}

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

/**
 * Create a line plot frame./*  w ww  . ja va 2s. c om*/
 *
 * @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.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java

/**
 *
 *//*from   ww w.j a va 2s  .co m*/
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:de.codesourcery.eve.skills.ui.components.impl.PriceHistoryComponent.java

private JPanel createFreeChartPanel2() {

    /*/*from w  w  w  . j a va  2s.  c o  m*/
     * Price plot.
     */
    final StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();

    renderer1.setDrawSeriesLineAsPath(false);
    final ValueAxis priceAxis = new NumberAxis("ISK");

    currentDataSets.pricePlot = new XYPlot(currentDataSets.prices, null, priceAxis, renderer1);

    currentDataSets.pricePlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    /*
     * Buy/sell volume plot.
     */

    final StandardXYItemRenderer renderer2 = // XYBarRenderer
            new StandardXYItemRenderer();

    final ValueAxis volumeAxis = new NumberAxis("Units");

    TimeSeriesCollection volumes = new TimeSeriesCollection();

    volumes.addSeries(currentDataSets.buyVolume);
    volumes.addSeries(currentDataSets.sellVolume);

    currentDataSets.volumePlot = new XYPlot(volumes, null, volumeAxis, renderer2);

    currentDataSets.volumePlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    /*
     * Combined plot.
     */

    final ValueAxis dateAxis = new DateAxis("Date");

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis);
    plot.setGap(10.0);
    plot.add(currentDataSets.pricePlot, 2);
    plot.add(currentDataSets.volumePlot, 1);

    plot.setOrientation(PlotOrientation.VERTICAL);

    /*
     * Create chart.
     */

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

    chart.setBackgroundPaint(Color.white);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));

    changeDateRange((DisplayRange) this.dateRangeChooser.getSelectedItem());

    // display chart
    ChartPanel chartPanel = new ChartPanel(chart);
    //      chartPanel.setMouseZoomable(true, false);
    return chartPanel;
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private XYDataset getDataset(String key, TimeSeries series) throws KeyedException {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.setXPosition(TimePeriodAnchor.START);
    dataset.addSeries(series);
    return dataset;
}

From source file:oscar.form.study.hsfo2.pageUtil.ManageHSFOAction.java

public void generateGraphs(HttpServletRequest request, HttpServletResponse response,
        Map<GraphDesc, TimeSeries> graphDescSeriesMap) {
    if (graphDescSeriesMap == null || graphDescSeriesMap.size() == 0)
        return;/*from   ww w  .  j a v a  2s  .c o  m*/

    OscarProperties props = OscarProperties.getInstance();
    String graphDirPath = props.getProperty("hsfo2.generategraph.dir", "/hsfo2Graphs");
    //graphDirPath = this.getServlet().getServletContext().getContextPath() + "/" + graphDirPath;
    //graphDirPath = request.getContextPath() + "/" + graphDirPath; 

    String graphDirRealPath = getServlet().getServletContext().getRealPath(graphDirPath);
    //make sure the directory exists
    File graphDir = new File(graphDirRealPath);
    if (!graphDir.exists() || !graphDir.isDirectory()) {
        graphDir.mkdirs();
    }

    for (Map.Entry<GraphDesc, TimeSeries> entry : graphDescSeriesMap.entrySet()) {
        //one dataset only contain one series here
        GraphDesc graphDesc = entry.getKey();
        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(entry.getValue());

        JFreeChart chart = ChartFactory.createTimeSeriesChart(graphDesc.getGraphTitle(),
                graphDesc.getXAxisLabel(), graphDesc.getYAxisLabel(), dataset, true, true, true);
        //might need to adjust the XYPlot, see Line 459 of MeasurementGraphAction2
        try {
            String fileName = graphDesc.getFileName() + "." + Calendar.getInstance().getTimeInMillis() + ".jpg";
            String realFilePath = graphDirRealPath + "/" + fileName;
            ChartUtilities.saveChartAsJPEG(new File(realFilePath), chart, 900, 200);
            logger.info("graph file: " + realFilePath + " generated and saved. ");

            request.setAttribute("graphFile." + graphDesc.getFileName(),
                    request.getContextPath() + "/" + graphDirPath + "/" + fileName);
        } catch (IOException e) {
            logger.error("Problem in creating chart: " + e.toString());
        }

    }
}

From source file:org.mwc.debrief.sensorfusion.views.DataSupport.java

public static void sensorDataFor(final TrackWrapper primary, final TimeSeriesCollection newData,
        final HashMap<SensorWrapper, SensorSeries> index) {

    index.clear();/*  www  . j  a v a 2 s .c o  m*/

    final Enumeration<Editable> sensors = primary.getSensors().elements();
    while (sensors.hasMoreElements()) {
        final SensorWrapper sensor = (SensorWrapper) sensors.nextElement();
        final SensorSeries series = new SensorSeries(sensor.getName(), sensor);
        final Enumeration<Editable> cuts = sensor.elements();
        _previousVal = Double.NaN;

        index.put(sensor, series);
        while (cuts.hasMoreElements()) {
            final SensorContactWrapper scw = (SensorContactWrapper) cuts.nextElement();
            final double thisVal = scw.getBearing();

            // wrap this in a try/catch - in case there are multiple entries
            try {
                series.add(create(scw.getTime(), thisVal, scw.getColor()));
            } catch (final Exception e) {
                // no probs, just ignore the new value
            }
        }

        if (!series.isEmpty())
            newData.addSeries(series);
    }
}

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

/**
 * Creates a sample dataset./*from w  ww  .  j  a v  a 2 s .  c  o  m*/
 *
 * @return the dataset.
 */
private XYDataset createDataset() {

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.setDomainIsPointsInTime(true);

    final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
    s1.add(new Minute(0, 0, 7, 12, 2003), 1.2);
    s1.add(new Minute(30, 12, 7, 12, 2003), 3.0);
    s1.add(new Minute(15, 14, 7, 12, 2003), 8.0);

    final TimeSeries s2 = new TimeSeries("Series 2", Minute.class);
    s2.add(new Minute(0, 3, 7, 12, 2003), 0.0);
    s2.add(new Minute(30, 9, 7, 12, 2003), 0.0);
    s2.add(new Minute(15, 10, 7, 12, 2003), 0.0);

    dataset.addSeries(s1);
    dataset.addSeries(s2);

    return dataset;

}

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

@Test
public void testGetRangeBounds2() {
    TimeZone tzone = TimeZone.getTimeZone("Europe/London");
    Calendar calendar = new GregorianCalendar(tzone, Locale.UK);
    calendar.clear();/*  w  w  w  .  ja v  a2s  . c  o m*/
    calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0);
    long start = calendar.getTimeInMillis();
    calendar.clear();
    calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0);
    long end = calendar.getTimeInMillis();
    Range range = new Range(start, end);

    TimeSeriesCollection collection = new TimeSeriesCollection(tzone);
    assertNull(collection.getRangeBounds(Collections.EMPTY_LIST, range, true));

    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Day(24, 2, 2014), 10.0);
    collection.addSeries(s1);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.MIDDLE);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.END);
    assertNull(collection.getRangeBounds(Arrays.asList("S1"), range, true));
}

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

/**
 * Some checks for the {@link TimeSeriesCollection#removeSeries(int)}
 * method.// www.  ja  v  a 2s .c  o  m
 */
@Test
public void testRemoveSeries_int() {
    TimeSeriesCollection c1 = new TimeSeriesCollection();
    TimeSeries s1 = new TimeSeries("Series 1");
    TimeSeries s2 = new TimeSeries("Series 2");
    TimeSeries s3 = new TimeSeries("Series 3");
    TimeSeries s4 = new TimeSeries("Series 4");
    c1.addSeries(s1);
    c1.addSeries(s2);
    c1.addSeries(s3);
    c1.addSeries(s4);
    c1.removeSeries(2);
    assertTrue(c1.getSeries(2).equals(s4));
    c1.removeSeries(0);
    assertTrue(c1.getSeries(0).equals(s2));
    assertEquals(2, c1.getSeriesCount());
}