Search in sources :

Example 1 with SeriesData

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

the class SeriesConverter method getSeriesScatter.

public static List<ISeriesData> getSeriesScatter(String fileName) {
    List<ISeriesData> scatterSeriesList = new ArrayList<ISeriesData>();
    // 
    BufferedReader bufferedReader = null;
    try {
        String line;
        bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
        while ((line = bufferedReader.readLine()) != null) {
            String[] values = line.split("\t");
            String id = values[0].trim();
            double[] xSeries = new double[] { Double.parseDouble(values[1].trim()) };
            double[] ySeries = new double[] { Double.parseDouble(values[2].trim()) };
            ISeriesData seriesData = new SeriesData(xSeries, ySeries, id);
            scatterSeriesList.add(seriesData);
        }
    } catch (Exception e) {
    // 
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
            // 
            }
        }
    }
    return scatterSeriesList;
}
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) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 2 with SeriesData

use of org.eclipse.swtchart.extensions.core.SeriesData 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 3 with SeriesData

use of org.eclipse.swtchart.extensions.core.SeriesData 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 4 with SeriesData

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

the class ScatterSeries_3_Part method initialize.

private void initialize() throws Exception {
    /*
		 * Chart Settings
		 */
    IChartSettings chartSettings = getChartSettings();
    RangeRestriction rangeRestriction = chartSettings.getRangeRestriction();
    rangeRestriction.setExtendTypeX(RangeRestriction.ExtendType.RELATIVE);
    rangeRestriction.setExtendMinX(0.25d);
    rangeRestriction.setExtendMaxX(0.1d);
    rangeRestriction.setExtendTypeY(RangeRestriction.ExtendType.RELATIVE);
    rangeRestriction.setExtendMinY(0.25d);
    rangeRestriction.setExtendMaxY(0.1d);
    rangeRestriction.setRestrictZoom(false);
    chartSettings.setCreateMenu(true);
    // 
    IPrimaryAxisSettings primaryAxisSettingsX = chartSettings.getPrimaryAxisSettingsX();
    primaryAxisSettingsX.setTitle("1st Dimension");
    primaryAxisSettingsX.setDecimalFormat(new DecimalFormat(("0"), new DecimalFormatSymbols(Locale.ENGLISH)));
    primaryAxisSettingsX.setColor(getDisplay().getSystemColor(SWT.COLOR_BLACK));
    // 
    IPrimaryAxisSettings primaryAxisSettingsY = chartSettings.getPrimaryAxisSettingsY();
    primaryAxisSettingsY.setTitle("2nd Dimension");
    primaryAxisSettingsY.setDecimalFormat(new DecimalFormat(("0.000"), new DecimalFormatSymbols(Locale.ENGLISH)));
    primaryAxisSettingsY.setColor(getDisplay().getSystemColor(SWT.COLOR_BLACK));
    // 
    applySettings(chartSettings);
    /*
		 * Create series.
		 */
    Map<Integer, Color> colors = new HashMap<Integer, Color>();
    colors.put(1, getDisplay().getSystemColor(SWT.COLOR_RED));
    colors.put(2, getDisplay().getSystemColor(SWT.COLOR_GRAY));
    colors.put(3, getDisplay().getSystemColor(SWT.COLOR_GREEN));
    colors.put(4, getDisplay().getSystemColor(SWT.COLOR_YELLOW));
    colors.put(5, getDisplay().getSystemColor(SWT.COLOR_CYAN));
    colors.put(6, getDisplay().getSystemColor(SWT.COLOR_BLUE));
    colors.put(7, getDisplay().getSystemColor(SWT.COLOR_BLACK));
    colors.put(8, getDisplay().getSystemColor(SWT.COLOR_DARK_MAGENTA));
    colors.put(9, getDisplay().getSystemColor(SWT.COLOR_DARK_CYAN));
    colors.put(10, getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN));
    colors.put(11, getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
    // 
    List<IScatterSeriesData> scatterSeriesDataList = new ArrayList<IScatterSeriesData>();
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 20; j++) {
            String id = "Series_" + i + "-" + j;
            int y = getRandomValue(10.0d);
            double[] xSeries = new double[] { i };
            double[] ySeries = new double[] { y };
            ISeriesData seriesData = new SeriesData(xSeries, ySeries, id);
            IScatterSeriesData scatterSeriesData = new ScatterSeriesData(seriesData);
            IScatterSeriesSettings scatterSeriesSettings = scatterSeriesData.getScatterSeriesSettings();
            scatterSeriesSettings.setDescription(id);
            scatterSeriesSettings.setSymbolSize(getRandomValue(30.0d));
            scatterSeriesSettings.setSymbolColor(colors.get(y));
            scatterSeriesSettings.setSymbolType(PlotSymbolType.CIRCLE);
            scatterSeriesDataList.add(scatterSeriesData);
        }
    }
    addSeriesData(scatterSeriesDataList);
}
Also used : IScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData) IScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData) ScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.ScatterSeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) DecimalFormatSymbols(java.text.DecimalFormatSymbols) IScatterSeriesSettings(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesSettings) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) SeriesData(org.eclipse.swtchart.extensions.core.SeriesData) IScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData) ScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.ScatterSeriesData) IChartSettings(org.eclipse.swtchart.extensions.core.IChartSettings) RangeRestriction(org.eclipse.swtchart.extensions.core.RangeRestriction) IPrimaryAxisSettings(org.eclipse.swtchart.extensions.core.IPrimaryAxisSettings)

Example 5 with SeriesData

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

the class LineSeries_Selection_Part method applyChartSettings.

private void applyChartSettings() throws Exception {
    /*
		 * Chart Settings
		 */
    IChartSettings chartSettings = lineChart.getChartSettings();
    chartSettings.setCreateMenu(true);
    /*
		 * Primary X-Axis
		 */
    IPrimaryAxisSettings primaryAxisSettingsX = chartSettings.getPrimaryAxisSettingsX();
    primaryAxisSettingsX.setTitle("Retention Time (milliseconds)");
    primaryAxisSettingsX.setDecimalFormat(new DecimalFormat(("0.0##"), new DecimalFormatSymbols(Locale.ENGLISH)));
    primaryAxisSettingsX.setColor(getDisplay().getSystemColor(SWT.COLOR_BLACK));
    /*
		 * Primary Y-Axis
		 */
    IPrimaryAxisSettings primaryAxisSettingsY = chartSettings.getPrimaryAxisSettingsY();
    primaryAxisSettingsY.setTitle("Intensity");
    primaryAxisSettingsY.setDecimalFormat(new DecimalFormat(("0.0#E0"), new DecimalFormatSymbols(Locale.ENGLISH)));
    primaryAxisSettingsY.setColor(getDisplay().getSystemColor(SWT.COLOR_BLACK));
    primaryAxisSettingsY.setGridLineStyle(LineStyle.NONE);
    /*
		 * Secondary Y-Axes
		 */
    ISecondaryAxisSettings secondaryAxisSettingsY1 = new SecondaryAxisSettings("Relative Intensity [%]", new RelativeIntensityConverter(SWT.VERTICAL, true));
    secondaryAxisSettingsY1.setPosition(Position.Secondary);
    secondaryAxisSettingsY1.setDecimalFormat(new DecimalFormat(("0.00"), new DecimalFormatSymbols(Locale.ENGLISH)));
    secondaryAxisSettingsY1.setColor(getDisplay().getSystemColor(SWT.COLOR_BLACK));
    chartSettings.getSecondaryAxisSettingsListY().add(secondaryAxisSettingsY1);
    // 
    lineChart.applySettings(chartSettings);
    /*
		 * Create series.
		 */
    List<ILineSeriesData> lineSeriesDataList = new ArrayList<ILineSeriesData>();
    ISeriesData seriesDataLine = SeriesConverter.getSeriesXY(SeriesConverter.LINE_SERIES_3);
    double[] xSeries = seriesDataLine.getXSeries();
    double[] ySeries = seriesDataLine.getYSeries();
    xValues = new TreeSet<Double>();
    yValues = new HashMap<Double, Double>();
    for (int i = 0; i < xSeries.length; i++) {
        double x = xSeries[i];
        xValues.add(x);
        yValues.put(x, ySeries[i]);
    }
    /*
		 * Line Series
		 */
    ILineSeriesData lineSeriesData;
    ILineSeriesSettings lineSeriesSettings;
    // 
    lineSeriesData = new LineSeriesData(seriesDataLine);
    lineSeriesSettings = lineSeriesData.getLineSeriesSettings();
    lineSeriesSettings.setEnableArea(true);
    ILineSeriesSettings lineSeriesSettingsHighlight = (ILineSeriesSettings) lineSeriesSettings.getSeriesSettingsHighlight();
    lineSeriesSettingsHighlight.setLineWidth(2);
    lineSeriesDataList.add(lineSeriesData);
    /*
		 * Selected Point
		 */
    seriesDataPoint = new SeriesData(new double[] { 0.0 }, new double[] { 0.0 }, DATA_POINT_SERIES);
    lineSeriesData = new LineSeriesData(seriesDataPoint);
    lineSeriesSettings = lineSeriesData.getLineSeriesSettings();
    lineSeriesSettings.setSymbolSize(5);
    lineSeriesSettings.setSymbolType(PlotSymbolType.CROSS);
    lineSeriesSettings.setEnableArea(true);
    lineSeriesDataList.add(lineSeriesData);
    /*
		 * Set series.
		 */
    lineChart.addSeriesData(lineSeriesDataList);
}
Also used : ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) RelativeIntensityConverter(org.eclipse.swtchart.extensions.axisconverter.RelativeIntensityConverter) ILineSeriesData(org.eclipse.swtchart.extensions.linecharts.ILineSeriesData) LineSeriesData(org.eclipse.swtchart.extensions.linecharts.LineSeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ILineSeriesSettings(org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings) ILineSeriesData(org.eclipse.swtchart.extensions.linecharts.ILineSeriesData) LineSeriesData(org.eclipse.swtchart.extensions.linecharts.LineSeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) SeriesData(org.eclipse.swtchart.extensions.core.SeriesData) ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) SecondaryAxisSettings(org.eclipse.swtchart.extensions.core.SecondaryAxisSettings) ILineSeriesData(org.eclipse.swtchart.extensions.linecharts.ILineSeriesData) IChartSettings(org.eclipse.swtchart.extensions.core.IChartSettings) IPrimaryAxisSettings(org.eclipse.swtchart.extensions.core.IPrimaryAxisSettings)

Aggregations

ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)8 SeriesData (org.eclipse.swtchart.extensions.core.SeriesData)8 BufferedReader (java.io.BufferedReader)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 IChartSettings (org.eclipse.swtchart.extensions.core.IChartSettings)2 IPrimaryAxisSettings (org.eclipse.swtchart.extensions.core.IPrimaryAxisSettings)2 HashMap (java.util.HashMap)1 Color (org.eclipse.swt.graphics.Color)1 RelativeIntensityConverter (org.eclipse.swtchart.extensions.axisconverter.RelativeIntensityConverter)1 ISecondaryAxisSettings (org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings)1 RangeRestriction (org.eclipse.swtchart.extensions.core.RangeRestriction)1 SecondaryAxisSettings (org.eclipse.swtchart.extensions.core.SecondaryAxisSettings)1 ILineSeriesData (org.eclipse.swtchart.extensions.linecharts.ILineSeriesData)1 ILineSeriesSettings (org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings)1 LineSeriesData (org.eclipse.swtchart.extensions.linecharts.LineSeriesData)1