Search in sources :

Example 1 with LineChart

use of org.eclipse.swtchart.extensions.linecharts.LineChart in project swtchart by eclipse.

the class RScriptExportHandler method execute.

@Override
public void execute(Shell shell, ScrollableChart scrollableChart) {
    BaseChart baseChart = scrollableChart.getBaseChart();
    /*
		 * Select the export file.
		 */
    FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
    fileDialog.setOverwrite(true);
    fileDialog.setText(TITLE);
    fileDialog.setFilterExtensions(new String[] { FILE_EXTENSION });
    // 
    String fileName = fileDialog.open();
    if (fileName != null) {
        /*
			 * Select the X and Y axis to export.
			 */
        ExportSettingsDialog exportSettingsDialog = new ExportSettingsDialog(shell, baseChart);
        exportSettingsDialog.create();
        if (exportSettingsDialog.open() == Window.OK) {
            // 
            int indexAxisX = exportSettingsDialog.getIndexAxisSelectionX();
            int indexAxisY = exportSettingsDialog.getIndexAxisSelectionY();
            // 
            if (indexAxisX >= 0 && indexAxisY >= 0) {
                /*
					 * X Axis Settings
					 */
                IAxisSettings axisSettingsX = baseChart.getXAxisSettings(indexAxisX);
                IAxisScaleConverter axisScaleConverterX = null;
                if (axisSettingsX instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsX;
                    axisScaleConverterX = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Y Axis Settings
					 */
                IAxisSettings axisSettingsY = baseChart.getYAxisSettings(indexAxisY);
                IAxisScaleConverter axisScaleConverterY = null;
                if (axisSettingsY instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsY;
                    axisScaleConverterY = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Print the XY data.
					 */
                PrintWriter printWriter = null;
                try {
                    printWriter = new PrintWriter(new File(fileName));
                    /*
						 * Axis settings.
						 */
                    AxisSettings axisSettings = new AxisSettings();
                    axisSettings.setIndexAxisX(indexAxisX);
                    axisSettings.setIndexAxisY(indexAxisY);
                    axisSettings.setAxisSettingsX(axisSettingsX);
                    axisSettings.setAxisScaleConverterX(axisScaleConverterX);
                    axisSettings.setAxisSettingsY(axisSettingsY);
                    axisSettings.setAxisScaleConverterY(axisScaleConverterY);
                    axisSettings.setExportVisibleOnly(exportSettingsDialog.isExportVisibleOnly());
                    // 
                    if (scrollableChart instanceof LineChart) {
                        printLinePlot(fileName, printWriter, scrollableChart, axisSettings);
                    } else if (scrollableChart instanceof BarChart) {
                        printBarPlot(fileName, printWriter, scrollableChart, axisSettings);
                    } else if (scrollableChart instanceof ScatterChart) {
                        printScatterPlot(fileName, printWriter, scrollableChart, axisSettings);
                    }
                    // 
                    printWriter.flush();
                    MessageDialog.openInformation(shell, TITLE, MESSAGE_OK);
                } catch (FileNotFoundException e) {
                    MessageDialog.openError(shell, TITLE, MESSAGE_ERROR);
                    System.out.println(e);
                } finally {
                    if (printWriter != null) {
                        printWriter.close();
                    }
                }
            }
        }
    }
}
Also used : ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) ScatterChart(org.eclipse.swtchart.extensions.scattercharts.ScatterChart) FileNotFoundException(java.io.FileNotFoundException) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) Point(org.eclipse.swt.graphics.Point) BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) BarChart(org.eclipse.swtchart.extensions.barcharts.BarChart) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) LineChart(org.eclipse.swtchart.extensions.linecharts.LineChart) PrintWriter(java.io.PrintWriter)

Example 2 with LineChart

use of org.eclipse.swtchart.extensions.linecharts.LineChart in project swtchart by eclipse.

the class LineSeries_Preferences_Part method initialize.

private void initialize() throws Exception {
    this.setLayout(new GridLayout(1, true));
    /*
		 * Buttons
		 */
    Composite compositeButtons = new Composite(this, SWT.NONE);
    GridData gridDataComposite = new GridData(GridData.FILL_HORIZONTAL);
    gridDataComposite.horizontalAlignment = SWT.END;
    compositeButtons.setLayoutData(gridDataComposite);
    compositeButtons.setLayout(new GridLayout(1, false));
    // 
    Button buttonOpenSettings = new Button(compositeButtons, SWT.PUSH);
    modifySettingsButton(buttonOpenSettings);
    buttonOpenSettings.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IPreferencePage preferencePage = new LineSeriesPreferencePage();
            preferencePage.setTitle("Chart Settings");
            IPreferencePage preferencePrimaryAxesPage = new LineSeriesPrimaryAxesPreferencePage();
            preferencePrimaryAxesPage.setTitle("Primary Axes");
            IPreferencePage preferenceSecondaryAxesPage = new LineSeriesSecondaryAxesPreferencePage();
            preferenceSecondaryAxesPage.setTitle("Secondary Axes");
            IPreferencePage preferenceDataPage = new LineSeriesDataPreferencePage();
            preferenceDataPage.setTitle("Series Data");
            // 
            PreferenceManager preferenceManager = new PreferenceManager();
            preferenceManager.addToRoot(new PreferenceNode("1", preferencePage));
            preferenceManager.addToRoot(new PreferenceNode("2", preferencePrimaryAxesPage));
            preferenceManager.addToRoot(new PreferenceNode("3", preferenceSecondaryAxesPage));
            preferenceManager.addToRoot(new PreferenceNode("4", preferenceDataPage));
            // 
            PreferenceDialog preferenceDialog = new PreferenceDialog(e.display.getActiveShell(), preferenceManager);
            preferenceDialog.create();
            preferenceDialog.setMessage("Settings");
            if (preferenceDialog.open() == Window.OK) {
                try {
                    applyChartSettings();
                    applySeriesSettings();
                } catch (Exception e1) {
                    System.out.println(e1);
                }
            }
        }
    });
    // 
    lineChart = new LineChart(this, SWT.NONE);
    lineChart.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 
    applyChartSettings();
    applySeriesSettings();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LineSeriesPrimaryAxesPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.LineSeriesPrimaryAxesPreferencePage) PreferenceNode(org.eclipse.jface.preference.PreferenceNode) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) LineSeriesDataPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.LineSeriesDataPreferencePage) GridLayout(org.eclipse.swt.layout.GridLayout) LineSeriesPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.LineSeriesPreferencePage) LineSeriesSecondaryAxesPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.LineSeriesSecondaryAxesPreferencePage) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IPreferencePage(org.eclipse.jface.preference.IPreferencePage) LineChart(org.eclipse.swtchart.extensions.linecharts.LineChart)

Example 3 with LineChart

use of org.eclipse.swtchart.extensions.linecharts.LineChart in project swtchart by eclipse.

the class LineSeries_Selection_Part method initialize.

private void initialize() throws Exception {
    this.setLayout(new GridLayout(1, true));
    this.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
    // 
    Composite compositeInfo = new Composite(this, SWT.NONE);
    GridData gridDataComposite = new GridData(GridData.FILL_HORIZONTAL);
    gridDataComposite.horizontalAlignment = SWT.BEGINNING;
    compositeInfo.setLayoutData(gridDataComposite);
    compositeInfo.setLayout(new GridLayout(13, false));
    // 
    createLabel(compositeInfo, "X-Start:");
    textRangeXStart = createText(compositeInfo);
    createLabel(compositeInfo, "X-Stop:");
    textRangeXStop = createText(compositeInfo);
    createLabel(compositeInfo, "Y-Start:");
    textRangeYStart = createText(compositeInfo);
    createLabel(compositeInfo, "Y-Stop:");
    textRangeYStop = createText(compositeInfo);
    createLabel(compositeInfo, "X:");
    textX = createText(compositeInfo);
    createLabel(compositeInfo, "Y:");
    textY = createText(compositeInfo);
    createButtonReset(compositeInfo);
    // 
    lineChart = new LineChart(this, SWT.NONE);
    lineChart.setLayoutData(new GridData(GridData.FILL_BOTH));
    lineChart.getBaseChart().addCustomRangeSelectionHandler(new ICustomSelectionHandler() {

        @Override
        public void handleUserSelection(Event event) {
            BaseChart baseChart = lineChart.getBaseChart();
            Range rangeX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange();
            Range rangeY = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange();
            DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, BaseChart.ID_PRIMARY_X_AXIS);
            DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, BaseChart.ID_PRIMARY_Y_AXIS);
            textRangeXStart.setText(decimalFormatX.format(rangeX.lower));
            textRangeXStop.setText(decimalFormatX.format(rangeX.upper));
            textRangeYStart.setText(decimalFormatY.format(rangeY.lower));
            textRangeYStop.setText(decimalFormatY.format(rangeY.upper));
        }
    });
    lineChart.getBaseChart().addCustomPointSelectionHandler(new ICustomSelectionHandler() {

        @Override
        public void handleUserSelection(Event event) {
            BaseChart baseChart = lineChart.getBaseChart();
            double x = baseChart.getSelectedPrimaryAxisValue(event.x, IExtendedChart.X_AXIS);
            double y = baseChart.getSelectedPrimaryAxisValue(event.y, IExtendedChart.Y_AXIS);
            // 
            DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, BaseChart.ID_PRIMARY_X_AXIS);
            DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, BaseChart.ID_PRIMARY_Y_AXIS);
            textX.setText(decimalFormatX.format(x));
            textY.setText(decimalFormatY.format(y));
            // 
            try {
                ISeries series = baseChart.getSeriesSet().getSeries(DATA_POINT_SERIES);
                double xSelected = xValues.floor(x);
                double ySelected = yValues.get(xSelected);
                double[] xSeries = new double[] { xSelected };
                double[] ySeries = new double[] { ySelected };
                series.setXSeries(xSeries);
                series.setYSeries(ySeries);
                baseChart.redraw();
            } catch (Exception e) {
            // 
            }
        }
    });
    applyChartSettings();
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ICustomSelectionHandler(org.eclipse.swtchart.extensions.core.ICustomSelectionHandler) DecimalFormat(java.text.DecimalFormat) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries) LineChart(org.eclipse.swtchart.extensions.linecharts.LineChart)

Aggregations

LineChart (org.eclipse.swtchart.extensions.linecharts.LineChart)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 DecimalFormat (java.text.DecimalFormat)1 IPreferencePage (org.eclipse.jface.preference.IPreferencePage)1 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)1 PreferenceManager (org.eclipse.jface.preference.PreferenceManager)1 PreferenceNode (org.eclipse.jface.preference.PreferenceNode)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 Point (org.eclipse.swt.graphics.Point)1 Button (org.eclipse.swt.widgets.Button)1 Event (org.eclipse.swt.widgets.Event)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 ISeries (org.eclipse.swtchart.ISeries)1