Multiple Series in a "timeseries" chart

Help
2003-01-23
2013-01-13
  • Scott Dippold
    Scott Dippold
    2003-01-23

    I'm able to generate a "timeseries" chart with one series (similar to the example), but when I try to add multiple series to the same "timeseries" chart it only charts the last series.  My DatasetProducer makes three queries into Oracle to pull datasets all based on time.  After I create the three series, I'm returning them similar to:

    return new TimeSeriesCollection(ts1);
    return new TimeSeriesCollection(ts2);
    return new TimeSeriesCollection(ts3);

    I noticed that JFreeChart has the ability to do this with this type of code:

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(ts1);
    dataset.addSeries(ts2);
    dataset.addSeries(ts3);

    Is there any way I can do something similar to this with cewolf?  If so, doesn't anybody have an example.

    -Scott

     

    • Anonymous
      2003-01-23

      Scott,

      you do it in cewolf exactly as you would in JFreeChart. In your dataproducer create your 3 series t1, t2, t3 then add all three of them to your TimeseriesCollection with addSeries and do:

      return dataset;

      Works fine!

      Roland.

       
    • Scott Dippold
      Scott Dippold
      2003-01-24

      Roland,

      Thanks for the validation.  I found that I had a problem with my producer.  I'm able to get it working now.

      -Scott

       
    • Anurag Singh
      Anurag Singh
      2004-01-27

      hi,
      I am also trying to do the same. but facing difficulties. Can you please send me som eexample implementation for the same

      thanks

       
      • Barry Ries
        Barry Ries
        2004-01-29

        package de.laures.cewolf.example;

        import java.text.SimpleDateFormat;
        import java.util.Date;
        import java.util.Map;
        import java.io.Serializable;
        import org.jfree.data.CategoryDataset;
        import org.jfree.data.DefaultCategoryDataset;
        import de.laures.cewolf.DatasetProduceException;
        import de.laures.cewolf.DatasetProducer;
        import de.laures.cewolf.CategoryItemLinkGenerator;

        import org.apache.commons.logging.Log;
        import org.apache.commons.logging.LogFactory;
        import org.jfree.chart.entity.CategoryItemEntity;
        import org.jfree.chart.tooltips.CategoryToolTipGenerator;
        import de.laures.cewolf.example.*;

        public class CnikXYDataProducer implements DatasetProducer, Serializable
        {

            // These values would normally not be hard coded but produced by
            // some kind of data source like a database or a file
            Log log;

            public Object produceDataset(java.util.Map map) throws de.laures.cewolf.DatasetProduceException
            {
                //log.debug("producing data.");
                org.jfree.data.XYDataset dataset;
                org.jfree.data.time.TimeSeries timeseries = new org.jfree.data.time.TimeSeries("L&G European Index Trust", org.jfree.data.time.Year.class);
                timeseries.add(new org.jfree.data.time.Year(2001), 181.445);
                timeseries.add(new org.jfree.data.time.Year(2002), 381.445);
                timeseries.add(new org.jfree.data.time.Year(2003), 181.445);
                timeseries.add(new org.jfree.data.time.Year(2004), 681.445);
                timeseries.add(new org.jfree.data.time.Year(2005), 81.445);
                timeseries.add(new org.jfree.data.time.Year(2006), 181.445);
                timeseries.add(new org.jfree.data.time.Year(2007), 881.445);
                org.jfree.data.time.TimeSeries timeseries2 = new org.jfree.data.time.TimeSeries("L&G UK Index Trust", org.jfree.data.time.Year.class);
                timeseries2.add(new org.jfree.data.time.Year(2001), 81.445);
                timeseries2.add(new org.jfree.data.time.Year(2002), 76.445);
                timeseries2.add(new org.jfree.data.time.Year(2003), 44.445);
                timeseries2.add(new org.jfree.data.time.Year(2004), 677.44);
                timeseries2.add(new org.jfree.data.time.Year(2005), 346.445);
                timeseries2.add(new org.jfree.data.time.Year(2006), 181.44);
                timeseries2.add(new org.jfree.data.time.Year(2007), 12.445);
                org.jfree.data.time.TimeSeriesCollection timeseriescollection = new org.jfree.data.time.TimeSeriesCollection();
                // now add the time series to the collection
                timeseriescollection.addSeries(timeseries);
                timeseriescollection.addSeries(timeseries2);
                dataset = timeseriescollection;
                return dataset;
            }

            public boolean hasExpired(Map params, Date since) {       
                //log.debug(getClass().getName() + "hasExpired()");
                return (System.currentTimeMillis() - since.getTime())  > 5000;
            }

            public String getProducerId() {
                return "CnikXYDataProducer DatasetProducer";
            }
               
        }

         
        • jaypsXC5
          jaypsXC5
          2007-01-10

          Hi,

          I'm using DefaultCategoryDataset in the produceDataset method to generate my
          dataset.

          Can you show me an example code for adding multiple datasets using
          DefaultCategoryDataset?

          Thanks