hi,
i have a dynamic chart. in this chart i have two series who will receive a new value each 5 seconds. at a certain moment i need two put in one of the two series a part of the other series. once this copy was achieved i want the new entering values to be added at the end of the new copied series. and here is where i have some troubles... before i make the add(new Millisecond(), value) my series has x items. after the add(new Millisecond(), value) there is only one item left.
can someone halp me with this problem? how can i make a copy of a part of a series to another series and then add some new values at the end of this series?
thanks for helping me.
patrick
add() problem
Re: add() problem
Hi Patrick,
I'm not completely sure what you mean. Can you post some sample code that illustrates what you are trying to do?
Regards,
DG
I'm not completely sure what you mean. Can you post some sample code that illustrates what you are trying to do?
Regards,
DG
Re: add() problem
hi dave,
here some sample code that should illustrate what i'm actually trying to do. the original code is taken from the memoryusage example.
/**
* Adds an observation to the 'total memory' time series.
*
* @param y the total memory used.
*/
private void addTotalObservation(double y) {
allValues.add(new Millisecond(), y);
diffValues.add(new Millisecond(), y);
}
/**
* The data generator.
*/
class DataGenerator extends Timer implements ActionListener {
/**
* Constructor.
*/
DataGenerator() {
super(1000, null);
addActionListener(this);
}
/**
* Adds a new free/total memory reading to the dataset.
*
* @param event the action event.
*/
public void actionPerformed(ActionEvent event) {
long value = Runtime.getRuntime().totalMemory();
addTotalObservation((double)value*(Math.random()));
}
}
public void setUHistoryCount(int history, String name) {
int start;
int end;
lastHistoryCount = history;
lastSeriesName = name;
dataset.removeSeries(dataset.getSeries(0));
diffValues = new BasicTimeSeries(diffValues.getName(), diffValues.getTimePeriodClass());
if (history > allValues.getItemCount()) {
start = 0;
} else {
start = allValues.getItemCount()-history;
}
end = allValues.getItemCount()-1;
//i make a copy of a part of another series
diffValues = allValues.createCopy(start, end);
diffValues.setName(name);
//i have to change the historycount
diffValues.setHistoryCount(history);
//adding the series to the dataset
dataset.addSeries(diffValues);
// at this point of the code there are for example 10 items in the series diffValues, but if the program is entering the above addTotalObservation() method there is only one item left after adding a new value to the series
}
i hope this will give you an overview what i'm trying to do... thanks for helping me.
patrick.
here some sample code that should illustrate what i'm actually trying to do. the original code is taken from the memoryusage example.
/**
* Adds an observation to the 'total memory' time series.
*
* @param y the total memory used.
*/
private void addTotalObservation(double y) {
allValues.add(new Millisecond(), y);
diffValues.add(new Millisecond(), y);
}
/**
* The data generator.
*/
class DataGenerator extends Timer implements ActionListener {
/**
* Constructor.
*/
DataGenerator() {
super(1000, null);
addActionListener(this);
}
/**
* Adds a new free/total memory reading to the dataset.
*
* @param event the action event.
*/
public void actionPerformed(ActionEvent event) {
long value = Runtime.getRuntime().totalMemory();
addTotalObservation((double)value*(Math.random()));
}
}
public void setUHistoryCount(int history, String name) {
int start;
int end;
lastHistoryCount = history;
lastSeriesName = name;
dataset.removeSeries(dataset.getSeries(0));
diffValues = new BasicTimeSeries(diffValues.getName(), diffValues.getTimePeriodClass());
if (history > allValues.getItemCount()) {
start = 0;
} else {
start = allValues.getItemCount()-history;
}
end = allValues.getItemCount()-1;
//i make a copy of a part of another series
diffValues = allValues.createCopy(start, end);
diffValues.setName(name);
//i have to change the historycount
diffValues.setHistoryCount(history);
//adding the series to the dataset
dataset.addSeries(diffValues);
// at this point of the code there are for example 10 items in the series diffValues, but if the program is entering the above addTotalObservation() method there is only one item left after adding a new value to the series
}
i hope this will give you an overview what i'm trying to do... thanks for helping me.
patrick.