Search in sources :

Example 16 with IBarSeries

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

the class BarBoundsExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    final Chart chart = new Chart(parent, SWT.NONE);
    chart.getTitle().setText("Bar Bounds");
    // create bar series
    IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 1");
    series1.setYSeries(ySeries1);
    IBarSeries series2 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 2");
    series2.setYSeries(ySeries2);
    series2.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    // add mouse move listener to open tooltip on data point
    chart.getPlotArea().addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            for (ISeries series : chart.getSeriesSet().getSeries()) {
                Rectangle[] rs = ((IBarSeries) series).getBounds();
                for (int i = 0; i < rs.length; i++) {
                    if (rs[i] != null) {
                        if (rs[i].x < e.x && e.x < rs[i].x + rs[i].width && rs[i].y < e.y && e.y < rs[i].y + rs[i].height) {
                            setToolTipText(series, i);
                            return;
                        }
                    }
                }
            }
            chart.getPlotArea().setToolTipText(null);
        }

        private void setToolTipText(ISeries series, int index) {
            chart.getPlotArea().setToolTipText("Series: " + series.getId() + "\nValue: " + series.getYSeries()[index]);
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) IBarSeries(org.eclipse.swtchart.IBarSeries) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart)

Example 17 with IBarSeries

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

the class InteractiveChartExample method createPartControl.

/*
	 * @see WorkbenchPart#createPartControl(Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new FillLayout());
    // create an interactive chart
    chart = new InteractiveChart(parent, SWT.NONE);
    // set title
    chart.getTitle().setText("Sample Interactive Chart");
    // set category series
    chart.getAxisSet().getXAxis(0).enableCategory(true);
    chart.getAxisSet().getXAxis(0).setCategorySeries(categorySeries);
    // create line series 1
    ILineSeries lineSeries1 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series 1");
    lineSeries1.setYSeries(yLineSeries1);
    // create line series 2
    ILineSeries lineSeries2 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series 2");
    lineSeries2.setYSeries(yLineSeries2);
    lineSeries2.setLineColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
    // create bar series 1
    IBarSeries barSeries1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series 1");
    barSeries1.setYSeries(yBarSeries1);
    // create bar series 2
    IBarSeries barSeries2 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series 2");
    barSeries2.setYSeries(yBarSeries2);
    barSeries2.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
    // adjust the axis range
    chart.getAxisSet().adjustRange();
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) FillLayout(org.eclipse.swt.layout.FillLayout) InteractiveChart(org.eclipse.swtchart.extensions.charts.InteractiveChart)

Example 18 with IBarSeries

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

the class BarChartExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    // set titles
    chart.getTitle().setText("Bar Chart");
    chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
    chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");
    // create bar series
    IBarSeries barSeries = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series");
    barSeries.setYSeries(ySeries);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Chart(org.eclipse.swtchart.Chart)

Example 19 with IBarSeries

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

the class TmfPieChart method addPieSlice.

/**
 * Add a slice to the model
 *
 * @param label
 *            Label
 * @param value
 *            Value (numerical)
 * @param id
 *            the unique ID
 */
public void addPieSlice(String label, double value, String id) {
    PieSlice pieSlice = new PieSlice(label, value, id);
    IBarSeries<?> bs = (IBarSeries<?>) getSeriesSet().createSeries(SeriesType.BAR, id);
    Color sliceColor = REGISTRY.get(id);
    if (sliceColor == null) {
        fCurrentColor += 3;
        RGBAColor rgba = PALETTE.get().get(fCurrentColor % NUM_COLORS);
        REGISTRY.put(id, new RGB(rgba.getRed(), rgba.getGreen(), rgba.getBlue()));
        sliceColor = REGISTRY.get(id);
    }
    bs.setBarColor(sliceColor);
    fSlices.add(pieSlice);
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB)

Example 20 with IBarSeries

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

the class SwtBarChart method setSelection.

@Override
protected void setSelection(@NonNull Set<@NonNull Object> set) {
    super.setSelection(set);
    /* Set color of selected symbol */
    Iterator<Color> colorsIt = Iterators.cycle(COLORS);
    Iterator<Color> lightColorsIt = Iterators.cycle(COLORS_LIGHT);
    for (ISeries series : getChart().getSeriesSet().getSeries()) {
        /* Series color */
        Color lightColor = NonNullUtils.checkNotNull(lightColorsIt.next());
        Color color = NonNullUtils.checkNotNull(colorsIt.next());
        if (set.isEmpty()) {
            /* Put all symbols to the normal colors */
            ((IBarSeries) series).setBarColor(color);
        } else {
            /*
                 * Fill with light colors to represent the deselected state. The
                 * paint listener is then responsible for drawing the cross and
                 * the dark colors for the selection.
                 */
            ((IBarSeries) series).setBarColor(lightColor);
        }
    }
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ISeries(org.eclipse.swtchart.ISeries)

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