Search in sources :

Example 11 with IBarSeries

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

the class PieChart method addPieChartSeries.

/**
 * Add data to this Pie Chart. We'll build one pie chart for each value in the array provided. The val matrix must
 * have an array of an array of values. Ex. labels = {'a', 'b'} val = {{1,2,3}, {4,5,6}} This will create 3 pie
 * charts. For the first one, 'a' will be 1 and 'b' will be 4. For the second chart 'a' will be 2 and 'b' will be 5.
 * For the third 'a' will be 3 and 'b' will be 6.
 * @param labels The titles of each series. (These are not the same as titles given to pies.)
 * @param val New values.
 */
public void addPieChartSeries(String[] labels, double[][] val) {
    setSeriesNames(val[0].length);
    for (ISeries s : this.getSeriesSet().getSeries()) {
        this.getSeriesSet().deleteSeries(s.getId());
    }
    int size = Math.min(labels.length, val.length);
    for (int i = 0; i < size; i++) {
        IBarSeries s = (IBarSeries) this.getSeriesSet().createSeries(ISeries.SeriesType.BAR, labels[i]);
        double[] d = new double[val[i].length];
        for (int j = 0; j < val[i].length; j++) {
            d[j] = val[i][j];
        }
        s.setXSeries(d);
        if (customColors != null) {
            s.setBarColor(customColors[i % customColors.length]);
        } else {
            s.setBarColor(new Color(this.getDisplay(), sliceColor(i)));
        }
    }
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ISeries(org.eclipse.swtchart.ISeries)

Example 12 with IBarSeries

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

the class BarChartBuilder method createChartISeries.

@Override
protected ISeries createChartISeries(int i) {
    IBarSeries series = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, adapter.getLabels()[i + 1]);
    series.setBarColor(COLORS[i % COLORS.length]);
    return series;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries)

Example 13 with IBarSeries

use of org.eclipse.swtchart.IBarSeries 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)

Example 14 with IBarSeries

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

the class PlotArea method paintControl.

/*
	 * @see PaintListener#paintControl(PaintEvent)
	 */
public void paintControl(PaintEvent e) {
    Point p = getSize();
    GC gc = e.gc;
    // draw the plot area background
    Color oldBackground = gc.getBackground();
    gc.setBackground(getBackground());
    gc.fillRectangle(0, 0, p.x, p.y);
    // draw grid
    for (IAxis axis : chart.getAxisSet().getAxes()) {
        ((Grid) axis.getGrid()).draw(gc, p.x, p.y);
    }
    // draw behind series
    for (ICustomPaintListener listener : paintListeners) {
        if (listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    // draw series. The line series should be drawn on bar series.
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof IBarSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof ILineSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    // draw over series
    for (ICustomPaintListener listener : paintListeners) {
        if (!listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    e.gc.setBackground(oldBackground);
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) ISeries(org.eclipse.swtchart.ISeries) Series(org.eclipse.swtchart.internal.series.Series) ICustomPaintListener(org.eclipse.swtchart.ICustomPaintListener) IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis)

Example 15 with IBarSeries

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

the class StackSeriesExample 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("Stack Series");
    chart.getAxisSet().getXAxis(0).getTitle().setText("Month");
    chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");
    // set category
    chart.getAxisSet().getXAxis(0).enableCategory(true);
    chart.getAxisSet().getXAxis(0).setCategorySeries(new String[] { "Jan", "Feb", "Mar", "Apr", "May" });
    // create bar series
    IBarSeries barSeries1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series 1");
    barSeries1.setYSeries(ySeries1);
    barSeries1.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
    IBarSeries barSeries2 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series 2");
    barSeries2.setYSeries(ySeries2);
    // enable stack series
    barSeries1.enableStack(true);
    barSeries2.enableStack(true);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Chart(org.eclipse.swtchart.Chart)

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