use of org.eclipse.swtchart.IBarSeries in project org.eclipse.linuxtools by eclipse-linuxtools.
the class PieChart method addPieChartSeries.
/**
* Add data to this Pie Chart. We'll build one pie chart for each value in the array provided. The val matrix must
* have an array of an array of values. Ex. labels = {'a', 'b'} val = {{1,2,3}, {4,5,6}} This will create 3 pie
* charts. For the first one, 'a' will be 1 and 'b' will be 4. For the second chart 'a' will be 2 and 'b' will be 5.
* For the third 'a' will be 3 and 'b' will be 6.
* @param labels The titles of each series. (These are not the same as titles given to pies.)
* @param val New values.
*/
public void addPieChartSeries(String[] labels, double[][] val) {
setSeriesNames(val[0].length);
for (ISeries s : this.getSeriesSet().getSeries()) {
this.getSeriesSet().deleteSeries(s.getId());
}
int size = Math.min(labels.length, val.length);
for (int i = 0; i < size; i++) {
IBarSeries s = (IBarSeries) this.getSeriesSet().createSeries(ISeries.SeriesType.BAR, labels[i]);
double[] d = new double[val[i].length];
for (int j = 0; j < val[i].length; j++) {
d[j] = val[i][j];
}
s.setXSeries(d);
if (customColors != null) {
s.setBarColor(customColors[i % customColors.length]);
} else {
s.setBarColor(new Color(this.getDisplay(), sliceColor(i)));
}
}
}
use of org.eclipse.swtchart.IBarSeries in project org.eclipse.linuxtools by eclipse-linuxtools.
the class BarChartBuilder method createChartISeries.
@Override
protected ISeries createChartISeries(int i) {
IBarSeries series = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, adapter.getLabels()[i + 1]);
series.setBarColor(COLORS[i % COLORS.length]);
return series;
}
use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class BarChart method addSeriesData.
/**
* BarWidthStyle.STRETCHED will be used automatically instead of BarWidthStyle.FIXED
* if the series data is too large. This leads to a better performance.
*
* @param barSeriesDataList
*/
public void addSeriesData(List<IBarSeriesData> barSeriesDataList, int compressToLength) {
/*
* Suspend the update when adding new data to improve the performance.
*/
if (barSeriesDataList != null && barSeriesDataList.size() > 0) {
BaseChart baseChart = getBaseChart();
baseChart.suspendUpdate(true);
for (IBarSeriesData barSeriesData : barSeriesDataList) {
/*
* Get the series data and apply the settings.
*/
try {
ISeriesData seriesData = barSeriesData.getSeriesData();
ISeriesData optimizedSeriesData = calculateSeries(seriesData, compressToLength);
IBarSeriesSettings barSeriesSettings = barSeriesData.getBarSeriesSettings();
// Initialize
barSeriesSettings.getSeriesSettingsHighlight();
IBarSeries barSeries = (IBarSeries) createSeries(optimizedSeriesData, barSeriesSettings);
baseChart.applyBarSeriesSettings(barSeries, barSeriesSettings);
/*
* Automatically use stretched if it is a large data set.
*/
if (isLargeDataSet(optimizedSeriesData.getXSeries(), optimizedSeriesData.getYSeries(), LENGTH_HINT_DATA_POINTS)) {
barSeries.setBarWidthStyle(BarWidthStyle.STRETCHED);
} else {
barSeries.setBarWidthStyle(barSeriesSettings.getBarWidthStyle());
}
} catch (SeriesException e) {
//
}
}
baseChart.suspendUpdate(false);
adjustRange(true);
baseChart.redraw();
}
}
use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class PlotArea method paintControl.
/*
* @see PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent e) {
Point p = getSize();
GC gc = e.gc;
// draw the plot area background
Color oldBackground = gc.getBackground();
gc.setBackground(getBackground());
gc.fillRectangle(0, 0, p.x, p.y);
// draw grid
for (IAxis axis : chart.getAxisSet().getAxes()) {
((Grid) axis.getGrid()).draw(gc, p.x, p.y);
}
// draw behind series
for (ICustomPaintListener listener : paintListeners) {
if (listener.drawBehindSeries()) {
listener.paintControl(e);
}
}
// draw series. The line series should be drawn on bar series.
for (ISeries series : chart.getSeriesSet().getSeries()) {
if (series instanceof IBarSeries) {
((Series) series).draw(gc, p.x, p.y);
}
}
for (ISeries series : chart.getSeriesSet().getSeries()) {
if (series instanceof ILineSeries) {
((Series) series).draw(gc, p.x, p.y);
}
}
// draw over series
for (ICustomPaintListener listener : paintListeners) {
if (!listener.drawBehindSeries()) {
listener.paintControl(e);
}
}
e.gc.setBackground(oldBackground);
}
use of org.eclipse.swtchart.IBarSeries in project swtchart by eclipse.
the class StackSeriesExample 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("Stack Series");
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);
// enable stack series
barSeries1.enableStack(true);
barSeries2.enableStack(true);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
Aggregations