use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class LegendBoundsExample 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("Legend Bounds");
// create bar series
IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 1");
series1.setYSeries(ySeries1);
series1.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
IBarSeries series2 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 2");
series2.setYSeries(ySeries2);
series2.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_MAGENTA));
IBarSeries series3 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 3");
series3.setYSeries(ySeries3);
// adjust the axis range
chart.getAxisSet().adjustRange();
// add mouse move listener to legend
final Control legend = (Control) chart.getLegend();
legend.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
for (ISeries series : chart.getSeriesSet().getSeries()) {
Rectangle r = chart.getLegend().getBounds(series.getId());
if (r.x < e.x && e.x < r.x + r.width && r.y < e.y && e.y < r.y + r.height) {
legend.setToolTipText(series.getId());
return;
}
}
}
});
return chart;
}
use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class OrientationExample 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 the chart orientation
chart.setOrientation(SWT.VERTICAL);
// set titles
chart.getTitle().setText("Orientation");
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 swtchart by eclipse.
the class AxisTickBoundsExample 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("Axis Tick Bounds");
// create bar series
IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series");
series1.setYSeries(ySeries);
// adjust the axis range
chart.getAxisSet().adjustRange();
// add mouse move listener to chart
chart.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
for (IAxis axis : chart.getAxisSet().getAxes()) {
Rectangle r = axis.getTick().getBounds();
// check if mouse cursor is on axis tick
if (r.x < e.x && e.x < r.x + r.width && r.y < e.y && e.y < r.y + r.height) {
// get pixel coordinate on axis tick
int pixelCoord;
if (axis.getDirection() == Direction.X) {
pixelCoord = e.x - r.x;
} else {
pixelCoord = e.y - r.y;
}
// get data coordinate
double dataCoord = axis.getDataCoordinate(pixelCoord);
// show tool-tip
chart.setToolTipText(String.valueOf(dataCoord));
return;
}
}
chart.setToolTipText(null);
}
});
return chart;
}
use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class CategoryExample 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("Category Axis");
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);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class BaseChart method applySeriesSettings.
private void applySeriesSettings(ISeries dataSeries, ISeriesSettings seriesSettings) {
if (dataSeries instanceof ILineSeries) {
ILineSeries lineSeries = (ILineSeries) dataSeries;
if (seriesSettings instanceof ILineSeriesSettings) {
/*
* Line Series
*/
ILineSeriesSettings lineSeriesSettings = (ILineSeriesSettings) seriesSettings;
applyLineSeriesSettings(lineSeries, lineSeriesSettings);
} else if (seriesSettings instanceof IScatterSeriesSettings) {
/*
* Scatter Series
*/
IScatterSeriesSettings scatterSeriesSettings = (IScatterSeriesSettings) seriesSettings;
applyScatterSeriesSettings(lineSeries, scatterSeriesSettings);
}
} else if (dataSeries instanceof IBarSeries) {
/*
* Bar Series
*/
IBarSeries barSeries = (IBarSeries) dataSeries;
IBarSeriesSettings barSeriesSettings = (IBarSeriesSettings) seriesSettings;
applyBarSeriesSettings(barSeries, barSeriesSettings);
}
}
Aggregations