Search in sources :

Example 1 with XYDataItem

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();
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) XYDataItem(org.jfree.data.xy.XYDataItem)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 XYDataItem (org.jfree.data.xy.XYDataItem)1 XYSeries (org.jfree.data.xy.XYSeries)1 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)1