use of org.jfree.data.xy.XYDataItem in project openblocks by mikaelhg.
the class CLineGraph method getCSV.
public String getCSV() {
lock = true;
int max = 0;
List<List<String>> columns = new ArrayList<List<String>>();
for (int i = 0; i < chartData.getSeriesNum(); i++) {
if (i == 0) {
//{name, v1, v2, v3}
List<String> time = new ArrayList<String>();
XYSeries s = ((XYSeriesCollection) chart.getXYPlot().getDataset()).getSeries(i);
max = Math.max(max, s.getItemCount());
time.add("TIME,");
for (Object o : s.getItems()) {
XYDataItem item = (XYDataItem) o;
time.add(item.getX() + ",");
}
columns.add(time);
}
//{name, v1, v2, v3}
List<String> values = new ArrayList<String>();
XYSeries s = ((XYSeriesCollection) chart.getXYPlot().getDataset()).getSeries(i);
max = Math.max(max, s.getItemCount());
values.add(s.getKey().toString() + ",");
for (Object o : s.getItems()) {
XYDataItem item = (XYDataItem) o;
values.add(item.getY() + ",");
}
columns.add(values);
}
StringBuilder output = new StringBuilder();
for (int i = 0; i < max; i++) {
for (int j = 0; j < columns.size(); j++) {
if (i < columns.get(j).size()) {
output.append(columns.get(j).get(i));
} else {
output.append(",");
}
}
output.append("\n");
}
lock = false;
return output.toString();
}
Aggregations