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