Java Examples for org.swtchart.IAxis
The following java examples will help you to understand the usage of org.swtchart.IAxis. These source code samples are taken from different open source projects.
Example 1
| Project: stocks-master File: ReturnsVolatilityChartView.java View source code |
@Override
protected Composite createBody(Composite parent) {
cache = make(DataSeriesCache.class);
Composite composite = new Composite(parent, SWT.NONE);
composite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
resources = new LocalResourceManager(JFaceResources.getResources(), composite);
chart = new ScatterChart(composite);
chart.getTitle().setVisible(false);
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.getTitle().setText(Messages.LabelVolatility);
//$NON-NLS-1$
xAxis.getTick().setFormat(new DecimalFormat("0.##%"));
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getTitle().setText(Messages.LabelPeformanceTTWROR);
//$NON-NLS-1$
yAxis.getTick().setFormat(new DecimalFormat("0.##%"));
((IPlotArea) chart.getPlotArea()).addCustomPaintListener(new ICustomPaintListener() {
@Override
public void paintControl(PaintEvent e) {
int y = xAxis.getPixelCoordinate(0);
e.gc.drawLine(y, 0, y, e.height);
int x = yAxis.getPixelCoordinate(0);
e.gc.drawLine(0, x, e.width, x);
}
@Override
public boolean drawBehindSeries() {
return true;
}
});
configurator = new DataSeriesConfigurator(this, DataSeries.UseCase.RETURN_VOLATILITY);
configurator.addListener(() -> updateChart());
DataSeriesChartLegend legend = new DataSeriesChartLegend(composite, configurator);
//$NON-NLS-1$ //$NON-NLS-2$
updateTitle(Messages.LabelHistoricalReturnsAndVolatiltity + " (" + configurator.getConfigurationName() + ")");
chart.getTitle().setText(getTitle());
GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 0).applyTo(composite);
GridDataFactory.fillDefaults().grab(true, true).applyTo(chart);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.FILL).applyTo(legend);
setChartSeries();
return composite;
}Example 2
| Project: swtchart-master File: ChartLayout.java View source code |
/**
* Parses the controls on given composite.
*
* @param composite
* the composite
* @return true if all children found
*/
private boolean parseControls(Composite composite) {
Control[] children = composite.getChildren();
axes.clear();
for (Control child : children) {
if (child instanceof Legend) {
legend = (Legend) child;
} else if (child instanceof ChartTitle) {
title = (ChartTitle) child;
} else if (child instanceof PlotArea) {
plot = (PlotArea) child;
}
}
if (composite instanceof Chart) {
IAxisSet axisSet = ((Chart) composite).getAxisSet();
if (axisSet != null) {
IAxis[] axisArray = axisSet.getAxes();
for (IAxis axis : axisArray) {
axes.add((Axis) axis);
}
}
}
if (title == null || legend == null || plot == null || axes.size() < 2) {
// the initialization of chart is not completed yet
return false;
}
return true;
}Example 3
| Project: linuxtools-master File: TestCreateSystemtapScript.java View source code |
private static void discreteXControlTests(AbstractChartBuilder cb, int numAxisItems) {
// Check that default range shows 100% of data.
IAxis axis = cb.getChart().getAxisSet().getXAxis(0);
Range range = axis.getRange();
double scale = cb.getScale();
double scroll = cb.getScroll();
assertTrue(range.upper - range.lower == axis.getCategorySeries().length - 1 && range.upper - range.lower == numAxisItems - 1);
assertTrue(scale == 1.0 && scroll == 1.0);
// Check that scroll buttons are disabled at 100% range.
SWTBotButton firstButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_First);
SWTBotButton leftButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Left);
SWTBotButton rightButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Right);
SWTBotButton lastButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Last);
assertFalse(firstButton.isEnabled());
assertFalse(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// Test zooming in. The amount of zoom is arbitrary for this test--just make sure zooming happened.
SWTBotButton zoomInButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomIn);
SWTBotButton zoomOutButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomOut);
SWTBotButton allButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_All);
assertTrue(zoomInButton.isEnabled());
assertFalse(zoomOutButton.isEnabled());
assertFalse(allButton.isEnabled());
zoomInButton.click();
assertTrue(zoomOutButton.isEnabled());
assertTrue(allButton.isEnabled());
// By default, zooming in should zoom in on the end of the axis (newest data).
range = axis.getRange();
assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScale() < scale && cb.getScroll() == 1.0);
// Left scrolling should now be enabled.
assertTrue(firstButton.isEnabled());
assertTrue(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// Test scrolling left. Again, the specific amount is arbitrary, just make sure scrolling happened.
leftButton.click();
range = axis.getRange();
assertTrue(range.upper < numAxisItems - 1 && cb.getScroll() < scroll);
int rstore = (int) range.lower;
assertTrue(rightButton.isEnabled());
assertTrue(lastButton.isEnabled());
// Zooming out should bring the range back to 100%.
zoomOutButton.click();
range = axis.getRange();
assertTrue(range.upper - range.lower == numAxisItems - 1 && cb.getScale() == 1.0 && cb.getScroll() < scroll);
assertTrue(zoomInButton.isEnabled());
assertFalse(zoomOutButton.isEnabled());
assertFalse(allButton.isEnabled());
assertFalse(firstButton.isEnabled());
assertFalse(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// For convenience, zooming out after having scrolled somewhere should make zooming in
// zoom back to the area that was scrolled to.
scroll = cb.getScroll();
zoomInButton.click();
assertTrue(rstore == axis.getRange().lower && scroll == cb.getScroll());
// Scrolling right should take the range back to the end of the axis.
rightButton.click();
range = axis.getRange();
assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScroll() > scroll);
assertTrue(firstButton.isEnabled());
assertTrue(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// and step right/left. Add a loop limit for safety.
for (int i = 0; i < numAxisItems; i++) {
range = axis.getRange();
if (range.upper == range.lower) {
break;
}
zoomInButton.click();
}
range = axis.getRange();
assertTrue(range.upper == range.lower && range.upper == numAxisItems - 1);
assertTrue(!zoomInButton.isEnabled());
for (int i = 0; i < numAxisItems; i++) {
if (axis.getRange().lower == 0) {
break;
}
leftButton.click();
assertTrue(axis.getRange().lower < range.lower);
range = axis.getRange();
assertEquals(range.lower, range.upper, 0.0);
}
assertEquals(axis.getRange().lower, 0, 0.0);
for (int i = 0; i < numAxisItems; i++) {
if (axis.getRange().upper == numAxisItems - 1) {
break;
}
rightButton.click();
assertTrue(axis.getRange().upper > range.upper);
range = axis.getRange();
assertEquals(range.lower, range.upper, 0.0);
}
assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
firstButton.click();
assertEquals(axis.getRange().lower, 0, 0);
assertFalse(firstButton.isEnabled());
assertFalse(leftButton.isEnabled());
assertTrue(rightButton.isEnabled());
assertTrue(lastButton.isEnabled());
lastButton.click();
assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
assertTrue(firstButton.isEnabled());
assertTrue(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
}Example 4
| Project: usus-plugins-master File: HistogramView.java View source code |
private void initializeChart() {
ILineSeries series = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, SERIES_ID);
series.setLineStyle(LineStyle.NONE);
series.setSymbolColor(getSharedColors().getColor(UsusColors.USUS_LIGHT_BLUE));
chart.getTitle().setVisible(false);
chart.getLegend().setVisible(false);
chart.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
chart.setBackgroundInPlotArea(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getTitle().setText("Count");
yAxis.getTitle().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
yAxis.getTick().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.getTitle().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
xAxis.getTick().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
}Example 5
| Project: tracecompass-master File: AbstractSegmentStoreDensityViewer.java View source code |
private void updateDisplay(List<ISegment> data) {
if (data.isEmpty()) {
return;
}
IBarSeries series = (IBarSeries) fChart.getSeriesSet().createSeries(SeriesType.BAR, Messages.AbstractSegmentStoreDensityViewer_SeriesLabel);
series.setVisible(true);
series.setBarPadding(0);
series.setBarColor(new Color(Display.getDefault(), BAR_COLOR));
int barWidth = 4;
final int width = fChart.getPlotArea().getBounds().width / barWidth;
double[] xOrigSeries = new double[width];
double[] yOrigSeries = new double[width];
Arrays.fill(yOrigSeries, 1.0);
long maxLength = data.get(data.size() - 1).getLength();
double maxFactor = 1.0 / (maxLength + 1.0);
long minX = Long.MAX_VALUE;
for (ISegment segment : data) {
double xBox = segment.getLength() * maxFactor * width;
yOrigSeries[(int) xBox]++;
minX = Math.min(minX, segment.getLength());
}
double timeWidth = (double) maxLength / (double) width;
for (int i = 0; i < width; i++) {
xOrigSeries[i] = i * timeWidth;
}
double maxY = Double.MIN_VALUE;
for (int i = 0; i < width; i++) {
maxY = Math.max(maxY, yOrigSeries[i]);
}
if (minX == maxLength) {
maxLength++;
minX--;
}
series.setYSeries(yOrigSeries);
series.setXSeries(xOrigSeries);
final IAxis xAxis = fChart.getAxisSet().getXAxis(0);
/*
* adjustrange appears to bring origin back since we pad the series with
* 0s, not interesting.
*/
xAxis.adjustRange();
Range range = xAxis.getRange();
// fix for overly aggressive lower after an adjust range
range.lower = minX - range.upper + maxLength;
xAxis.setRange(range);
xAxis.getTick().setFormat(DENSITY_TIME_FORMATTER);
fChart.getAxisSet().getYAxis(0).setRange(new Range(1.0, maxY));
fChart.getAxisSet().getYAxis(0).enableLogScale(true);
fChart.redraw();
}Example 6
| Project: acs-master File: AlarmsPerTenMinutesPart.java View source code |
public void createPartControl(Composite parent) {
chart = new Chart(parent, SWT.NONE);
ITitle chartTitle = chart.getTitle();
chartTitle.setText("Alarms per 10 minutes");
IAxisSet axisSet = chart.getAxisSet();
IAxis[] xAxis = axisSet.getXAxes();
ITitle xTitle = xAxis[0].getTitle();
xTitle.setText("Time");
IAxis[] yAxis = axisSet.getYAxes();
ITitle yTitle = yAxis[0].getTitle();
yTitle.setText("# alarms");
ISeriesSet seriesSet = chart.getSeriesSet();
nAlarmsSerie = (ILineSeries) seriesSet.createSeries(SeriesType.LINE, "nAlarms");
nAlarmsSerie.enableStep(true);
nAlarmsSerie.setSymbolType(PlotSymbolType.NONE);
IAxisTick xTick = axisSet.getXAxis(0).getTick();
DateFormat format = new SimpleDateFormat("HH:mm");
xTick.setFormat(format);
errorSerie = (ILineSeries) seriesSet.createSeries(SeriesType.LINE, "Threshold");
errorSerie.setSymbolType(PlotSymbolType.NONE);
errorColor = new Color(Display.getDefault(), 255, 0, 0);
errorSerie.setLineColor(errorColor);
TenMinutesContainer.getInstance().setChartViewer(this);
}Example 7
| Project: framesoc-master File: TmfMouseSelectionProvider.java View source code |
// ------------------------------------------------------------------------
// ICustomPaintListener
// ------------------------------------------------------------------------
@Override
public void paintControl(PaintEvent e) {
ITmfChartTimeProvider viewer = getChartViewer();
if (!fIsInternalUpdate) {
fBeginTime = viewer.getSelectionBeginTime() - viewer.getTimeOffset();
fEndTime = viewer.getSelectionEndTime() - viewer.getTimeOffset();
}
long windowStartTime = viewer.getWindowStartTime() - viewer.getTimeOffset();
long windowEndTime = viewer.getWindowEndTime() - viewer.getTimeOffset();
IAxis xAxis = getChart().getAxisSet().getXAxis(0);
e.gc.setBackground(TmfXYChartViewer.getDisplay().getSystemColor(SWT.COLOR_BLUE));
e.gc.setForeground(TmfXYChartViewer.getDisplay().getSystemColor(SWT.COLOR_BLUE));
e.gc.setLineStyle(SWT.LINE_SOLID);
if ((fBeginTime >= windowStartTime) && (fBeginTime <= windowEndTime)) {
int beginX = xAxis.getPixelCoordinate(fBeginTime);
e.gc.drawLine(beginX, 0, beginX, e.height);
}
if ((fEndTime >= windowStartTime) && (fEndTime <= windowEndTime) && (fBeginTime != fEndTime)) {
int endX = xAxis.getPixelCoordinate(fEndTime);
e.gc.drawLine(endX, 0, endX, e.height);
}
e.gc.setAlpha(150);
if (Math.abs(fEndTime - fBeginTime) > 1) {
e.gc.setBackground(TmfXYChartViewer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
int beginX = xAxis.getPixelCoordinate(fBeginTime);
int endX = xAxis.getPixelCoordinate(fEndTime);
if (fEndTime > fBeginTime) {
e.gc.fillRectangle(beginX + 1, 0, endX - beginX - 1, e.height);
} else {
e.gc.fillRectangle(endX + 1, 0, beginX - endX - 1, e.height);
}
}
}Example 8
| Project: limpet-master File: DataFrequencyView.java View source code |
private void showObject(List<IStoreItem> res) {
Iterator<IStoreItem> iter = res.iterator();
// clear the graph
ISeries[] coll = chart.getSeriesSet().getSeries();
for (int i = 0; i < coll.length; i++) {
ISeries iSeries = coll[i];
chart.getSeriesSet().deleteSeries(iSeries.getId());
}
while (iter.hasNext()) {
ICollection iCollection = (ICollection) iter.next();
if (iCollection.getValuesCount() <= MAX_SIZE) {
BinnedData bins = null;
IObjectCollection<?> thisQ = (IObjectCollection<?>) iCollection;
bins = ObjectFrequencyBins.doBins(thisQ);
String seriesName = iCollection.getName();
IBarSeries newSeries = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, seriesName);
newSeries.setBarColor(PlottingHelpers.colorFor(seriesName));
String[] xData = new String[bins.size()];
double[] yData = new double[bins.size()];
// put the data into series
int ctr = 0;
Iterator<ObjectFrequencyBins.Bin> iter2 = bins.iterator();
while (iter2.hasNext()) {
ObjectFrequencyBins.Bin bin = (ObjectFrequencyBins.Bin) iter2.next();
xData[ctr] = (String) bin.getIndexVal();
yData[ctr++] = bin.getFreqVal();
}
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.setCategorySeries(xData);
xAxis.enableCategory(true);
// newSeries.set(xData);
newSeries.setYSeries(yData);
// adjust the axis range
chart.getAxisSet().adjustRange();
chart.redraw();
}
}
}Example 9
| Project: totalads-master File: LiveXYChart.java View source code |
/**
* Sets minimum and maximum on Y axis
*
* @param min
* Minimum value
* @param max
* Maximum value
*/
public void setYRange(final int min, final int max) {
Display.getDefault().syncExec(new // Always execute on the
Runnable() {
// main GUI thread
@Override
public void run() {
IAxis yAxis = fXyChart.getAxisSet().getYAxis(0);
yAxis.setRange(new Range(min, max));
yAxis.getTick().setTickMarkStepHint(100);
// fXyChart.getAxisSet().adjustRange();
}
});
}Example 10
| Project: ARX-master File: ViewStatisticsLogisticRegression.java View source code |
/**
* Resets the chart
*/
private void resetChart() {
if (chart != null) {
chart.dispose();
}
chart = new Chart(this.sash, SWT.NONE);
chart.setOrientation(SWT.HORIZONTAL);
// Show/Hide axis
chart.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent arg0) {
updateCategories();
}
});
// Update font
FontData[] fd = chart.getFont().getFontData();
fd[0].setHeight(8);
final Font font = new Font(chart.getDisplay(), fd[0]);
chart.setFont(font);
chart.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
if (font != null && !font.isDisposed()) {
font.dispose();
}
}
});
// Update title
ITitle graphTitle = chart.getTitle();
//$NON-NLS-1$
graphTitle.setText("");
graphTitle.setFont(chart.getFont());
// Set colors
chart.setBackground(root.getBackground());
chart.setForeground(root.getForeground());
// OSX workaround
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
//$NON-NLS-1$ //$NON-NLS-2$
int r = chart.getBackground().getRed() - 13;
int g = chart.getBackground().getGreen() - 13;
int b = chart.getBackground().getBlue() - 13;
r = r > 0 ? r : 0;
r = g > 0 ? g : 0;
r = b > 0 ? b : 0;
final Color background = new Color(chart.getDisplay(), r, g, b);
chart.setBackground(background);
chart.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
if (background != null && !background.isDisposed()) {
background.dispose();
}
}
});
}
// Initialize axes
IAxisSet axisSet = chart.getAxisSet();
IAxis yAxis = axisSet.getYAxis(0);
IAxis xAxis = axisSet.getXAxis(0);
ITitle xAxisTitle = xAxis.getTitle();
//$NON-NLS-1$
xAxisTitle.setText("");
xAxis.getTitle().setFont(chart.getFont());
yAxis.getTitle().setFont(chart.getFont());
xAxis.getTick().setFont(chart.getFont());
yAxis.getTick().setFont(chart.getFont());
xAxis.getTick().setForeground(chart.getForeground());
yAxis.getTick().setForeground(chart.getForeground());
xAxis.getTitle().setForeground(chart.getForeground());
yAxis.getTitle().setForeground(chart.getForeground());
// Initialize axes
ITitle yAxisTitle = yAxis.getTitle();
//$NON-NLS-1$
yAxisTitle.setText(Resources.getMessage("ViewStatisticsClassificationInput.17"));
//$NON-NLS-1$
xAxisTitle.setText(Resources.getMessage("ViewStatisticsClassificationInput.14"));
chart.setEnabled(false);
updateCategories();
}Example 11
| Project: org.openscada.orilla-master File: AbstractTrendView.java View source code |
private void adjustRange() {
if (this.scaleYAutomatically) {
final Pair<Double, Double> scale = calcScale();
this.scaleYMin = scale.first;
this.scaleYMax = scale.second;
updateSpinner();
}
for (final IAxis axis : this.chart.getAxisSet().getXAxes()) {
axis.adjustRange();
}
for (final IAxis axis : this.chart.getAxisSet().getYAxes()) {
axis.setRange(new Range(this.scaleYMin, this.scaleYMax));
}
}