Search in sources :

Example 6 with ISeriesData

use of org.eclipse.swtchart.extensions.core.ISeriesData in project swtchart by eclipse.

the class LineChart method addSeriesData.

/**
 * The data is compressed to the given length.
 * If you're unsure which length to set, then use one of the following variables:
 *
 * HIGH_COMPRESSION
 * MEDIUM_COMPRESSION
 * LOW_COMPRESSION
 * NO_COMPRESSION
 *
 * @param lineSeriesDataList
 * @param compressToLength
 */
public void addSeriesData(List<ILineSeriesData> lineSeriesDataList, int compressToLength) {
    /*
		 * Suspend the update when adding new data to improve the performance.
		 */
    if (lineSeriesDataList != null && lineSeriesDataList.size() > 0) {
        BaseChart baseChart = getBaseChart();
        baseChart.suspendUpdate(true);
        for (ILineSeriesData lineSeriesData : lineSeriesDataList) {
            /*
				 * Get the series data and apply the settings.
				 */
            try {
                ISeriesData seriesData = lineSeriesData.getSeriesData();
                ISeriesData optimizedSeriesData = calculateSeries(seriesData, compressToLength);
                ILineSeriesSettings lineSeriesSettings = lineSeriesData.getLineSeriesSettings();
                // Initialize
                lineSeriesSettings.getSeriesSettingsHighlight();
                ILineSeries lineSeries = (ILineSeries) createSeries(optimizedSeriesData, lineSeriesSettings);
                baseChart.applyLineSeriesSettings(lineSeries, lineSeriesSettings);
            } catch (SeriesException e) {
            // 
            }
        }
        baseChart.suspendUpdate(false);
        adjustRange(true);
        baseChart.redraw();
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) ILineSeries(org.eclipse.swtchart.ILineSeries) SeriesException(org.eclipse.swtchart.extensions.exceptions.SeriesException)

Example 7 with ISeriesData

use of org.eclipse.swtchart.extensions.core.ISeriesData in project swtchart by eclipse.

the class ScatterChart method addSeriesData.

public void addSeriesData(List<IScatterSeriesData> scatterSeriesDataList) {
    /*
		 * Suspend the update when adding new data to improve the performance.
		 */
    if (scatterSeriesDataList != null && scatterSeriesDataList.size() > 0) {
        /*
			 * Set the data.
			 */
        BaseChart baseChart = getBaseChart();
        baseChart.suspendUpdate(true);
        for (IScatterSeriesData scatterSeriesData : scatterSeriesDataList) {
            /*
				 * Get the series data and apply the settings.
				 */
            try {
                ISeriesData seriesData = scatterSeriesData.getSeriesData();
                ISeriesData optimizedSeriesData = calculateSeries(seriesData, ScrollableChart.NO_COMPRESS_TO_LENGTH);
                IScatterSeriesSettings scatterSeriesSettings = scatterSeriesData.getScatterSeriesSettings();
                // Initialize
                scatterSeriesSettings.getSeriesSettingsHighlight();
                ILineSeries scatterSeries = (ILineSeries) createSeries(optimizedSeriesData, scatterSeriesSettings);
                baseChart.applyScatterSeriesSettings(scatterSeries, scatterSeriesSettings);
            } catch (SeriesException e) {
            // 
            }
        }
        baseChart.suspendUpdate(false);
        adjustRange(true);
        baseChart.redraw();
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) ILineSeries(org.eclipse.swtchart.ILineSeries) SeriesException(org.eclipse.swtchart.extensions.exceptions.SeriesException)

Example 8 with ISeriesData

use of org.eclipse.swtchart.extensions.core.ISeriesData in project swtchart by eclipse.

the class SeriesConverter method getSeriesXY.

public static ISeriesData getSeriesXY(String fileName, String id) {
    int size = getNumberOfLines(fileName);
    double[] xSeries = new double[size];
    double[] ySeries = new double[size];
    // 
    BufferedReader bufferedReader = null;
    try {
        String line;
        int i = 0;
        bufferedReader = new BufferedReader(new InputStreamReader(SeriesConverter.class.getResourceAsStream(fileName)));
        while ((line = bufferedReader.readLine()) != null) {
            if (!line.startsWith("#")) {
                String[] values = line.split("\t");
                xSeries[i] = Double.parseDouble(values[0].trim());
                ySeries[i] = Double.parseDouble(values[1].trim());
                i++;
            }
        }
    } catch (Exception e) {
    // 
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
            // 
            }
        }
    }
    // 
    ISeriesData seriesData = new SeriesData(xSeries, ySeries, id);
    return seriesData;
}
Also used : ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) SeriesData(org.eclipse.swtchart.extensions.core.SeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 9 with ISeriesData

use of org.eclipse.swtchart.extensions.core.ISeriesData in project swtchart by eclipse.

the class SeriesConverter method getSeriesFromY.

public static ISeriesData getSeriesFromY(String fileName) {
    int size = getNumberOfLines(fileName);
    double[] ySeries = new double[size];
    // 
    BufferedReader bufferedReader = null;
    try {
        String line;
        int i = 0;
        bufferedReader = new BufferedReader(new InputStreamReader(SeriesConverter.class.getResourceAsStream(fileName)));
        while ((line = bufferedReader.readLine()) != null) {
            ySeries[i++] = Double.parseDouble(line.trim());
        }
    } catch (Exception e) {
    // 
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
            // 
            }
        }
    }
    // 
    ISeriesData seriesData = new SeriesData(ySeries, fileName);
    return seriesData;
}
Also used : ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) SeriesData(org.eclipse.swtchart.extensions.core.SeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 10 with ISeriesData

use of org.eclipse.swtchart.extensions.core.ISeriesData in project swtchart by eclipse.

the class CustomLineChart1 method addDemoSeries.

private void addDemoSeries() {
    List<ILineSeriesData> lineSeriesDataList = new ArrayList<ILineSeriesData>();
    ISeriesData seriesData = SeriesConverter.getSeriesXY(seriesXY);
    // 
    ILineSeriesData lineSeriesData = new LineSeriesData(seriesData);
    ILineSeriesSettings lineSeriesSettings = lineSeriesData.getLineSeriesSettings();
    lineSeriesSettings.setEnableArea(true);
    ILineSeriesSettings lineSeriesSettingsHighlight = (ILineSeriesSettings) lineSeriesSettings.getSeriesSettingsHighlight();
    lineSeriesSettingsHighlight.setLineWidth(2);
    lineSeriesDataList.add(lineSeriesData);
    /*
		 * Set series.
		 */
    addSeriesData(lineSeriesDataList, LENGTH_HINT_DATA_POINTS);
}
Also used : ILineSeriesSettings(org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings) LineSeriesData(org.eclipse.swtchart.extensions.linecharts.LineSeriesData) ILineSeriesData(org.eclipse.swtchart.extensions.linecharts.ILineSeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) ILineSeriesData(org.eclipse.swtchart.extensions.linecharts.ILineSeriesData) ArrayList(java.util.ArrayList)

Aggregations

ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)44 ArrayList (java.util.ArrayList)37 IChartSettings (org.eclipse.swtchart.extensions.core.IChartSettings)24 ILineSeriesData (org.eclipse.swtchart.extensions.linecharts.ILineSeriesData)20 ILineSeriesSettings (org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings)20 LineSeriesData (org.eclipse.swtchart.extensions.linecharts.LineSeriesData)20 DecimalFormat (java.text.DecimalFormat)10 DecimalFormatSymbols (java.text.DecimalFormatSymbols)10 IPrimaryAxisSettings (org.eclipse.swtchart.extensions.core.IPrimaryAxisSettings)10 BarSeriesData (org.eclipse.swtchart.extensions.barcharts.BarSeriesData)9 IBarSeriesData (org.eclipse.swtchart.extensions.barcharts.IBarSeriesData)9 Color (org.eclipse.swt.graphics.Color)8 SeriesData (org.eclipse.swtchart.extensions.core.SeriesData)8 BufferedReader (java.io.BufferedReader)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 HashMap (java.util.HashMap)6 IScatterSeriesData (org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData)6 IScatterSeriesSettings (org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesSettings)6 ScatterSeriesData (org.eclipse.swtchart.extensions.scattercharts.ScatterSeriesData)6