Dynamic TimeTableXYDataset .. possible?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mentox
Posts: 9
Joined: Thu Jan 03, 2008 11:02 am

Dynamic TimeTableXYDataset .. possible?

Post by mentox » Thu Jan 03, 2008 3:17 pm

Hi,

I have tryied some different Datasets Charts and some other Stuff :-)


Now i am at the point to say i implement my own TableXYDataset if i must :-)

but what do i need to implement ..

i want an dynamic stackedarea chart .. which shows hits from the last mintute for each second ... i a new second is done the chart should scroll and remove the oldes entry..

to remove entries out of the TimeTableXYDataset is very komplex and not save :-( it can be that you forget some, because you cant sag remove all older than or some thing like this...

any one have an implementation or know wich interface i have to implement in this case?


thanks
with kind regards
dominique matz

mentox
Posts: 9
Joined: Thu Jan 03, 2008 11:02 am

Post by mentox » Fri Jan 04, 2008 8:20 am

Hello,

i have tryed some code ...


the chart is painting the axis with the rigth values but does the areas are not painted :-(

what do i wrong?

Code: Select all

import java.util.Date;
import java.util.TreeMap;

import org.jfree.data.DomainInfo;
import org.jfree.data.Range;
import org.jfree.data.xy.AbstractXYDataset;
import org.jfree.data.xy.TableXYDataset;

public class DynamicTimeTableXYDataset extends AbstractXYDataset implements TableXYDataset, DomainInfo {

    private static final long serialVersionUID = 1L;

    int countColumn = 5;

    TreeMap<Date, long[]> cache = new TreeMap<Date, long[]>();

    public DynamicTimeTableXYDataset() {
        for (int i = 0; i < countColumn; i++) {
            appendData(new Date(), new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void appendData(Date date, long[] data) {

        cache.put(date, data);

        while (cache.size() > countColumn) {
            cache.remove(cache.firstKey());
        }
        
        fireDatasetChanged();
    }

    @Override
    public int getItemCount() {
        return cache.size();
    }

    // @Override
    // public DomainOrder getDomainOrder() {
    // return DomainOrder.ASCENDING;
    // }

    @Override
    public int getItemCount(int series) {
        return cache.size();
    }

    @Override
    public int getSeriesCount() {
        return cache.firstEntry().getValue().length;
    }

    @Override
    public Comparable getSeriesKey(int series) {
        return String.valueOf(series);
    }

    @Override
    public Number getX(int series, int item) {
        return cache.get(cache.keySet().toArray()[item])[series];
    }

    @Override
    public Number getY(int series, int item) {
        return getX(series, item);
    }

    @Override
    public Range getDomainBounds(boolean includeInterval) {
        return new Range(getDomainLowerBound(true), getDomainUpperBound(true));
    }

    @Override
    public double getDomainLowerBound(boolean includeInterval) {
        return cache.firstKey().getTime();
    }

    @Override
    public double getDomainUpperBound(boolean includeInterval) {
        return cache.lastKey().getTime();
    }

}
if some one can use the code feel free to use it :-) this code has no license :-)

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Jan 04, 2008 12:41 pm

A couple of suggestions:

(1) Post a small demo app that uses this class, so we can just cut, paste, compile and run your code (instead of having to take a little more time to create our own running code);

(2) Check that you really mean to call getX() within the getY() method.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

mentox
Posts: 9
Joined: Thu Jan 03, 2008 11:02 am

Post by mentox » Mon Jan 07, 2008 12:45 pm

hi

where is the different between X and Y ...

i have only some series and for every a date with one value ..

i don know where ther is an x or y .. kann you help me or give me an url where i can read what x and y means .. how it is used

Locked