Hi, i have follow the guide to create a chart but i would insert data every 1 second in a Line chart… i have do it but this is the result.
- Paolo Mastrangelo asked 7 years ago
- last edited 7 years ago
-
That’s really strange. Can you share your code how you are Appending to the DataSeries please?
-
Shared :)
- You must login to post comments
Hi Paolo,
I took a look on your code and found the problem in insertData() method:
public void insertData() {
Random random = new Random();
long xValue = new Date().getTime() + DateIntervalUtil.fromDays(day);
xValues.add(new Date(xValue));
yValues.add(random.nextDouble());
//the data values can be appended to the DataSeries
dataSeries.append(xValues, yValues);
day++;
setZoomExtents(chartSurface_1);
}
When you append xValues and yValues they contain all previously added values. So first call of insertData() will append 1 data point, second will append 2 points(1 from previous call and 1 new data point), third call will append 3 points(2 from previous call and 1 new data point) and so on.
To fix this issue you just need to clear xValues/yValues collection before adding new points:
xValues.clear();
yValues.clear();
Hope it helps!
- Yura Khariton answered 7 years ago
- last edited 7 years ago
-
Fixed ;)
- You must login to post comments
Please login first to submit.