Search in sources :

Example 6 with IBarSeries

use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.

the class SeriesPage method apply.

/*
	 * @see AbstractPreferencePage#apply()
	 */
@Override
public void apply() {
    for (int i = 0; i < series.length; i++) {
        series[i].setVisible(visibleStates[i]);
        if (series[i] instanceof ILineSeries) {
            Color lineColor = new Color(Display.getDefault(), lineColors[i]);
            ((ILineSeries) series[i]).setLineColor(lineColor);
            final String lineColorKey = SERIES_LINE_COLOR + series[i].getId();
            if (resources.getColor(lineColorKey) == null) {
                series[i].addDisposeListener(new IDisposeListener() {

                    public void disposed(Event e) {
                        resources.removeColor(lineColorKey);
                    }
                });
            }
            resources.put(lineColorKey, lineColor);
            Color symbolColor = new Color(Display.getDefault(), symbolColors[i]);
            ((ILineSeries) series[i]).setSymbolColor(symbolColor);
            final String symbolColorKey = SERIES_SYMBOL_COLOR + series[i].getId();
            if (resources.getColor(symbolColorKey) == null) {
                series[i].addDisposeListener(new IDisposeListener() {

                    public void disposed(Event e) {
                        resources.removeColor(symbolColorKey);
                    }
                });
            }
            resources.put(symbolColorKey, symbolColor);
            ((ILineSeries) series[i]).setLineStyle(lineStyles[i]);
            ((ILineSeries) series[i]).setSymbolType(symbolTypes[i]);
            ((ILineSeries) series[i]).setSymbolSize(symbolSizes[i]);
        } else if (series[i] instanceof IBarSeries) {
            Color barColor = new Color(Display.getDefault(), barColors[i]);
            ((IBarSeries) series[i]).setBarColor(barColor);
            final String barColorKey = SERIES_BAR_COLOR + series[i].getId();
            if (resources.getColor(barColorKey) == null) {
                series[i].addDisposeListener(new IDisposeListener() {

                    public void disposed(Event e) {
                        resources.removeColor(barColorKey);
                    }
                });
            }
            resources.put(barColorKey, barColor);
            ((IBarSeries) series[i]).setBarPadding(paddings[i]);
        }
        try {
            series[i].enableStack(stackedStates[i]);
        } catch (IllegalArgumentException e) {
            stackedStates[i] = false;
            stackedButton.setSelection(false);
        }
        series[i].setXAxisId(xAxisIds[i]);
        series[i].setYAxisId(yAxisIds[i]);
    }
}
Also used : IDisposeListener(org.eclipse.swtchart.IDisposeListener) IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) Color(org.eclipse.swt.graphics.Color) Event(org.eclipse.swt.widgets.Event) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 7 with IBarSeries

use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.

the class Legend method drawSymbol.

/**
 * Draws the symbol of series.
 *
 * @param gc
 *            the graphics context
 * @param series
 *            the series
 * @param r
 *            the rectangle to draw the symbol of series
 */
protected void drawSymbol(GC gc, Series series, Rectangle r) {
    if (!visible) {
        return;
    }
    if (series instanceof ILineSeries) {
        // draw plot line
        gc.setForeground(((ILineSeries) series).getLineColor());
        gc.setLineWidth(LINE_WIDTH);
        int lineStyle = Util.getIndexDefinedInSWT(((ILineSeries) series).getLineStyle());
        int x = r.x;
        int y = r.y + r.height / 2;
        if (lineStyle != SWT.NONE) {
            gc.setLineStyle(lineStyle);
            gc.drawLine(x, y, x + SYMBOL_WIDTH, y);
        }
        // draw series symbol
        Color color = ((ILineSeries) series).getSymbolColor();
        Color[] colors = ((ILineSeries) series).getSymbolColors();
        if (colors != null && colors.length > 0) {
            color = colors[0];
        }
        ((LineSeries) series).drawSeriesSymbol(gc, x + SYMBOL_WIDTH / 2, y, color);
    } else if (series instanceof IBarSeries) {
        // draw riser
        gc.setBackground(((IBarSeries) series).getBarColor());
        int size = SYMBOL_WIDTH / 2;
        int x = r.x + size / 2;
        int y = (int) (r.y - size / 2d + r.height / 2d);
        gc.fillRectangle(x, y, size, size);
    }
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) LineSeries(org.eclipse.swtchart.internal.series.LineSeries)

Example 8 with IBarSeries

use of org.eclipse.swtchart.IBarSeries in project tracecompass by tracecompass.

the class SwtBarChart method createSwtSeries.

@Override
protected ISeries createSwtSeries(ChartSeries chartSeries, ISeriesSet swtSeriesSet, @NonNull Color color) {
    String title = chartSeries.getY().getLabel();
    IBarSeries swtSeries = (IBarSeries) swtSeriesSet.createSeries(SeriesType.BAR, title);
    swtSeries.setBarPadding(BAR_PADDING);
    swtSeries.setBarColor(color);
    return swtSeries;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries)

Example 9 with IBarSeries

use of org.eclipse.swtchart.IBarSeries in project olca-app by GreenDelta.

the class ContributionChart method createBar.

private void createBar(String id, double val, Color color, int width) {
    IBarSeries bars = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, id);
    bars.setYSeries(new double[] { val });
    bars.setBarColor(color);
    bars.setBarPadding(15);
    bars.setBarWidth(width);
    bars.setBarWidthStyle(BarWidthStyle.FIXED);
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries)

Example 10 with IBarSeries

use of org.eclipse.swtchart.IBarSeries in project org.eclipse.linuxtools by eclipse-linuxtools.

the class ChartFactory method produceBarChart.

/**
 * Produces a 2D bar chart from the input objects.
 *
 * @param objects
 *            the input data
 * @param nameField
 *            the field used to get the labels of the objects (the labels of the series groups).
 * @param valFields
 *            the fields providing the values for the different bars in a series group.
 * @param title Title of the chart.
 * @param horizontal
 *            if true the bars are displayed horizontally, else vertically.
 * @return a new 2D bar chart
 */
public static InteractiveChart produceBarChart(Object[] objects, final ISTDataViewersField nameField, List<IChartField> valFields, String title, boolean horizontal) {
    ChartView view;
    try {
        final Color WHITE = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE);
        final Color BLACK = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);
        final Color GRAD = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
        view = (ChartView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ChartView.VIEW_ID, String.valueOf(ChartView.getSecId()), IWorkbenchPage.VIEW_ACTIVATE);
        InteractiveChart chart = new InteractiveChart(view.getParent(), SWT.NONE);
        chart.setBackground(WHITE);
        chart.getPlotArea().setBackground(GRAD);
        chart.getTitle().setText(title);
        chart.getTitle().setForeground(BLACK);
        chart.setProposedSaveAsFilename(title.replace(' ', '_'));
        // this is correct (refers to orientation of x-axis, not bars)
        if (horizontal) {
            chart.setOrientation(SWT.VERTICAL);
        } else {
            chart.setOrientation(SWT.HORIZONTAL);
        }
        chart.getLegend().setPosition(SWT.RIGHT);
        String[] textLabels = new String[objects.length];
        for (int i = 0; i < objects.length; i++) {
            textLabels[i] = nameField.getValue(objects[i]);
        }
        // x-axis
        IAxis xAxis = chart.getAxisSet().getXAxis(0);
        xAxis.getGrid().setStyle(LineStyle.NONE);
        xAxis.getTick().setForeground(BLACK);
        ITitle xTitle = xAxis.getTitle();
        xTitle.setForeground(BLACK);
        xTitle.setText(nameField.getColumnHeaderText());
        xAxis.setCategorySeries(textLabels);
        xAxis.enableCategory(true);
        // y-axis
        IAxis yAxis = chart.getAxisSet().getYAxis(0);
        yAxis.getGrid().setStyle(LineStyle.NONE);
        yAxis.getTick().setForeground(BLACK);
        yAxis.getTitle().setVisible(false);
        // data
        for (IChartField field : valFields) {
            final IBarSeries bs = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, field.getColumnHeaderText());
            bs.setBarColor(new Color(Display.getDefault(), getRC(), getRC(), getRC()));
            double[] doubleValues = new double[objects.length];
            for (int i = 0; i < objects.length; i++) {
                Number num = field.getNumber(objects[i]);
                double longVal = num.doubleValue();
                doubleValues[i] = longVal;
            }
            bs.setYSeries(doubleValues);
        }
        chart.getAxisSet().adjustRange();
        return chart;
    } catch (PartInitException e) {
        Activator.getDefault().getLog().log(e.getStatus());
    }
    return null;
}
Also used : Color(org.eclipse.swt.graphics.Color) ITitle(org.eclipse.swtchart.ITitle) InteractiveChart(org.eclipse.swtchart.extensions.charts.InteractiveChart) IAxis(org.eclipse.swtchart.IAxis) IBarSeries(org.eclipse.swtchart.IBarSeries) IChartField(org.eclipse.linuxtools.dataviewers.charts.provider.IChartField) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IBarSeries (org.eclipse.swtchart.IBarSeries)20 Color (org.eclipse.swt.graphics.Color)7 Chart (org.eclipse.swtchart.Chart)7 ILineSeries (org.eclipse.swtchart.ILineSeries)5 ISeries (org.eclipse.swtchart.ISeries)5 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 IAxis (org.eclipse.swtchart.IAxis)3 Rectangle (org.eclipse.swt.graphics.Rectangle)2 InteractiveChart (org.eclipse.swtchart.extensions.charts.InteractiveChart)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 IChartField (org.eclipse.linuxtools.dataviewers.charts.provider.IChartField)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GC (org.eclipse.swt.graphics.GC)1 Point (org.eclipse.swt.graphics.Point)1 RGB (org.eclipse.swt.graphics.RGB)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Control (org.eclipse.swt.widgets.Control)1 Event (org.eclipse.swt.widgets.Event)1