Search in sources :

Example 26 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 file) {
    int size = getNumberOfLines(file);
    double[] xSeries = new double[size];
    double[] ySeries = new double[size];
    // 
    BufferedReader bufferedReader = null;
    try {
        String line;
        int i = 0;
        bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        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, file);
    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) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 27 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(new FileInputStream(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) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 28 with ISeriesData

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

the class ImageFactory_2_UITest method test1.

public void test1() {
    try {
        /*
			 * Create the factory.
			 */
        ImageFactory<MassSpectrumChart> imageFactory = new ImageFactory<MassSpectrumChart>(MassSpectrumChart.class, 800, 600);
        /*
			 * Modify the chart.
			 */
        MassSpectrumChart massSpectrumChart = imageFactory.getChart();
        massSpectrumChart.setBackground(massSpectrumChart.getBaseChart().getDisplay().getSystemColor(SWT.COLOR_WHITE));
        List<IBarSeriesData> barSeriesDataList = new ArrayList<IBarSeriesData>();
        ISeriesData seriesData = SeriesConverter.getSeriesXY(TestPathHelper.getAbsolutePath(TestPathHelper.TESTFILE_BAR_SERIES_1));
        // 
        IBarSeriesData barSeriesData = new BarSeriesData(seriesData);
        IBarSeriesSettings barSeriesSettings = barSeriesData.getBarSeriesSettings();
        barSeriesSettings.setDescription("");
        barSeriesDataList.add(barSeriesData);
        massSpectrumChart.addSeriesData(barSeriesDataList);
        /*
			 * Export the images.
			 */
        String exportFolder = TestPathHelper.getAbsolutePath(TestPathHelper.TESTFOLDER_EXPORT);
        String prefix = "BarSeries1";
        // 
        String png = exportFolder + File.separator + prefix + ".png";
        imageFactory.saveImage(png, SWT.IMAGE_PNG);
        File filePng = new File(png);
        assertTrue(filePng.exists());
        filePng.delete();
        // 
        String jpg = exportFolder + File.separator + prefix + ".jpg";
        imageFactory.saveImage(jpg, SWT.IMAGE_JPEG);
        File fileJpg = new File(jpg);
        assertTrue(fileJpg.exists());
        fileJpg.delete();
        // 
        String bmp = exportFolder + File.separator + prefix + ".bmp";
        imageFactory.saveImage(bmp, SWT.IMAGE_BMP);
        File fileBmp = new File(bmp);
        assertTrue(fileBmp.exists());
        fileBmp.delete();
        // 
        imageFactory.closeShell();
    // 
    } catch (InstantiationException e) {
        System.out.println(e);
    } catch (IllegalAccessException e) {
        System.out.println(e);
    }
}
Also used : ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) ArrayList(java.util.ArrayList) ImageFactory(org.eclipse.swtchart.extensions.images.ImageFactory) IBarSeriesSettings(org.eclipse.swtchart.extensions.barcharts.IBarSeriesSettings) IBarSeriesData(org.eclipse.swtchart.extensions.barcharts.IBarSeriesData) IBarSeriesData(org.eclipse.swtchart.extensions.barcharts.IBarSeriesData) BarSeriesData(org.eclipse.swtchart.extensions.barcharts.BarSeriesData) File(java.io.File) MassSpectrumChart(org.eclipse.swtchart.extensions.customcharts.MassSpectrumChart)

Example 29 with ISeriesData

use of org.eclipse.swtchart.extensions.core.ISeriesData 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(SeriesConverter.class.getResourceAsStream(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) IOException(java.io.IOException)

Example 30 with ISeriesData

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

the class BarChart method addSeriesData.

/**
 * BarWidthStyle.STRETCHED will be used automatically instead of BarWidthStyle.FIXED
 * if the series data is too large. This leads to a better performance.
 *
 * @param barSeriesDataList
 */
public void addSeriesData(List<IBarSeriesData> barSeriesDataList, int compressToLength) {
    /*
		 * Suspend the update when adding new data to improve the performance.
		 */
    if (barSeriesDataList != null && barSeriesDataList.size() > 0) {
        BaseChart baseChart = getBaseChart();
        baseChart.suspendUpdate(true);
        for (IBarSeriesData barSeriesData : barSeriesDataList) {
            /*
				 * Get the series data and apply the settings.
				 */
            try {
                ISeriesData seriesData = barSeriesData.getSeriesData();
                ISeriesData optimizedSeriesData = calculateSeries(seriesData, compressToLength);
                IBarSeriesSettings barSeriesSettings = barSeriesData.getBarSeriesSettings();
                // Initialize
                barSeriesSettings.getSeriesSettingsHighlight();
                IBarSeries barSeries = (IBarSeries) createSeries(optimizedSeriesData, barSeriesSettings);
                baseChart.applyBarSeriesSettings(barSeries, barSeriesSettings);
                /*
					 * Automatically use stretched if it is a large data set.
					 */
                if (isLargeDataSet(optimizedSeriesData.getXSeries(), optimizedSeriesData.getYSeries(), LENGTH_HINT_DATA_POINTS)) {
                    barSeries.setBarWidthStyle(BarWidthStyle.STRETCHED);
                } else {
                    barSeries.setBarWidthStyle(barSeriesSettings.getBarWidthStyle());
                }
            } 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) IBarSeries(org.eclipse.swtchart.IBarSeries) SeriesException(org.eclipse.swtchart.extensions.exceptions.SeriesException)

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