use of org.eclipse.swtchart.ILineSeries 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);
}
}
use of org.eclipse.swtchart.ILineSeries 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.ILineSeries in project swtchart by eclipse.
the class LineChart method addSeriesData.
/**
* The data is compressed to the given length.
* If you're unsure which length to set, then use one of the following variables:
*
* HIGH_COMPRESSION
* MEDIUM_COMPRESSION
* LOW_COMPRESSION
* NO_COMPRESSION
*
* @param lineSeriesDataList
* @param compressToLength
*/
public void addSeriesData(List<ILineSeriesData> lineSeriesDataList, int compressToLength) {
/*
* Suspend the update when adding new data to improve the performance.
*/
if (lineSeriesDataList != null && lineSeriesDataList.size() > 0) {
BaseChart baseChart = getBaseChart();
baseChart.suspendUpdate(true);
for (ILineSeriesData lineSeriesData : lineSeriesDataList) {
/*
* Get the series data and apply the settings.
*/
try {
ISeriesData seriesData = lineSeriesData.getSeriesData();
ISeriesData optimizedSeriesData = calculateSeries(seriesData, compressToLength);
ILineSeriesSettings lineSeriesSettings = lineSeriesData.getLineSeriesSettings();
// Initialize
lineSeriesSettings.getSeriesSettingsHighlight();
ILineSeries lineSeries = (ILineSeries) createSeries(optimizedSeriesData, lineSeriesSettings);
baseChart.applyLineSeriesSettings(lineSeries, lineSeriesSettings);
} catch (SeriesException e) {
//
}
}
baseChart.suspendUpdate(false);
adjustRange(true);
baseChart.redraw();
}
}
use of org.eclipse.swtchart.ILineSeries in project swtchart by eclipse.
the class ScatterChart method addSeriesData.
public void addSeriesData(List<IScatterSeriesData> scatterSeriesDataList) {
/*
* Suspend the update when adding new data to improve the performance.
*/
if (scatterSeriesDataList != null && scatterSeriesDataList.size() > 0) {
/*
* Set the data.
*/
BaseChart baseChart = getBaseChart();
baseChart.suspendUpdate(true);
for (IScatterSeriesData scatterSeriesData : scatterSeriesDataList) {
/*
* Get the series data and apply the settings.
*/
try {
ISeriesData seriesData = scatterSeriesData.getSeriesData();
ISeriesData optimizedSeriesData = calculateSeries(seriesData, ScrollableChart.NO_COMPRESS_TO_LENGTH);
IScatterSeriesSettings scatterSeriesSettings = scatterSeriesData.getScatterSeriesSettings();
// Initialize
scatterSeriesSettings.getSeriesSettingsHighlight();
ILineSeries scatterSeries = (ILineSeries) createSeries(optimizedSeriesData, scatterSeriesSettings);
baseChart.applyScatterSeriesSettings(scatterSeries, scatterSeriesSettings);
} catch (SeriesException e) {
//
}
}
baseChart.suspendUpdate(false);
adjustRange(true);
baseChart.redraw();
}
}
use of org.eclipse.swtchart.ILineSeries 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);
}
}
Aggregations