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]);
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations