use of org.eclipse.swtchart.Chart 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.Chart in project swtchart by eclipse.
the class PxielToDataConversionExample 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("Pxiel To Data Conversion");
// get axes
final IAxis xAxis = chart.getAxisSet().getXAxis(0);
final IAxis yAxis = chart.getAxisSet().getYAxis(0);
// create line series
ILineSeries series = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
series.setYSeries(ySeries);
// adjust the axis range
chart.getAxisSet().adjustRange();
// add mouse move listener to show mouse position on tooltip
chart.getPlotArea().addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
double x = xAxis.getDataCoordinate(e.x);
double y = yAxis.getDataCoordinate(e.y);
chart.getPlotArea().setToolTipText("x:" + x + ", y:" + y);
}
});
return chart;
}
use of org.eclipse.swtchart.Chart in project swtchart by eclipse.
the class AngledAxisTickLabelsExample 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);
chart.getTitle().setText("Angled Axis Tick Labels");
// set category
chart.getAxisSet().getXAxis(0).enableCategory(true);
chart.getAxisSet().getXAxis(0).setCategorySeries(cagetorySeries);
chart.getAxisSet().getXAxis(0).getTick().setTickLabelAngle(45);
// add bar series
ISeries barSeries = chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series");
barSeries.setYSeries(ySeries);
chart.getAxisSet().adjustRange();
return chart;
}
use of org.eclipse.swtchart.Chart in project swtchart by eclipse.
the class AreaChartExample 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("Area Chart");
// create line series
ILineSeries lineSeries1 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series 1");
lineSeries1.setYSeries(ySeries1);
lineSeries1.setLineColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
lineSeries1.enableArea(true);
ILineSeries lineSeries2 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series 2");
lineSeries2.setYSeries(ySeries2);
lineSeries2.enableArea(true);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
use of org.eclipse.swtchart.Chart 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;
}
Aggregations