Reputation: 1675
I have a TimeSeries chart, showing up some values per dates and there are two series which displays as two different lines. The problem is that sometimes one series does not contain values for some particular dates. In that case I assume that line will be continued from previous point to next on this series. Unfortunately it does not work correctly on chart, it looks like something wasn't drawn correctly at all.
If every series contains appropriate values per every date then it's fine.
My code is here:
for (String source : graphData.keySet()) {
SortedMap<LocalDate, BigDecimal> data = graphData.get(source);
LocalDate prevDate = null;
for (LocalDate date: data.keySet()) {
if (prevDate == null) {
prevDate = date;
continue;
}
dataset.add(new SimpleTimePeriod(prevDate.toDateMidnight().toDate(), date.toDateMidnight().toDate()), data.get(prevDate), source, true);
prevDate = date;
}
dataset.add(new SimpleTimePeriod(prevDate.toDateMidnight().toDate(), futureDate), data.get(prevDate), source, true);
}
Map<String, SortedMap<LocalDate, BigDecimal>> graphData
contains the data for all series, where key of the map is the series name.
And as I said - sometimes series A contains values for dates 1, 2 and 3, and series B only for 1 and 2. In that case line for A and B does not look properly...
Is there any easy way to fix that? The obvious and hard-to-implement way is to calculate the missed value for B series (using linear interpolation?) and put it to dataset, but it would be really very hard to do. Maybe I missed something?
Upvotes: 2
Views: 663
Reputation: 1675
Found out how to solve it - For every series create it's own dataset and renderer. Then, when creating a chart use any one dataset, and afterthat add all those datasets and renderers.
xyPlot.addDataset(0, firstDataset);
xyPlot.addDataset(1, secondDataset);
Or if there are can be a plenty series then it's better to do it in the cycle
Upvotes: 1
Reputation: 205785
The midpoint formula is a simple way to replace a single missing ordinate.
Upvotes: 2