use of org.swtchart.IBarSeries in project linuxtools by eclipse.
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.swtchart.IBarSeries in project portfolio by buchen.
the class TimelineChart method addDateBarSeries.
public IBarSeries addDateBarSeries(LocalDate[] dates, double[] values, String label) {
IBarSeries barSeries = (IBarSeries) getSeriesSet().createSeries(SeriesType.BAR, label);
barSeries.setXDateSeries(toJavaUtilDate(dates));
barSeries.setYSeries(values);
barSeries.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
barSeries.setBarPadding(100);
return barSeries;
}
use of org.swtchart.IBarSeries in project portfolio by buchen.
the class DividendsChartTab method createSeries.
@Override
protected void createSeries() {
for (int index = 0; index < model.getNoOfMonths(); index += 12) {
int year = model.getStartYear() + (index / 12);
IBarSeries barSeries = (IBarSeries) getChart().getSeriesSet().createSeries(SeriesType.BAR, String.valueOf(year));
double[] series = new double[Math.min(12, model.getNoOfMonths() - index)];
for (int ii = 0; ii < series.length; ii++) series[ii] = model.getSum().getValue(index + ii) / Values.Amount.divider();
barSeries.setYSeries(series);
barSeries.setBarColor(getColor(year));
barSeries.setBarPadding(25);
}
}
use of org.swtchart.IBarSeries in project linuxtools by eclipse.
the class ChartFactory method produceBarChart.
/**
* Produces a 2D bar chart from the input objects.
*
* @param objects
* the input data
* @param nameField
* the field used to get the labels of the objects (the labels of the series groups).
* @param valFields
* the fields providing the values for the different bars in a series group.
* @param title Title of the chart.
* @param horizontal
* if true the bars are displayed horizontally, else vertically.
* @return a new 2D bar chart
*/
public static Chart produceBarChart(Object[] objects, final ISTDataViewersField nameField, List<IChartField> valFields, String title, boolean horizontal) {
ChartView view;
try {
final Color WHITE = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE);
final Color BLACK = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);
final Color GRAD = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
view = (ChartView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ChartView.VIEW_ID, String.valueOf(ChartView.getSecId()), IWorkbenchPage.VIEW_ACTIVATE);
Chart chart = new Chart(view.getParent(), SWT.NONE);
chart.setBackground(WHITE);
chart.setBackgroundInPlotArea(GRAD);
chart.getTitle().setText(title);
chart.getTitle().setForeground(BLACK);
// this is correct (refers to orientation of x-axis, not bars)
if (horizontal) {
chart.setOrientation(SWT.VERTICAL);
} else {
chart.setOrientation(SWT.HORIZONTAL);
}
chart.getLegend().setPosition(SWT.RIGHT);
String[] textLabels = new String[objects.length];
for (int i = 0; i < objects.length; i++) {
textLabels[i] = nameField.getValue(objects[i]);
}
// x-axis
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.getGrid().setStyle(LineStyle.NONE);
xAxis.getTick().setForeground(BLACK);
ITitle xTitle = xAxis.getTitle();
xTitle.setForeground(BLACK);
xTitle.setText(nameField.getColumnHeaderText());
xAxis.setCategorySeries(textLabels);
xAxis.enableCategory(true);
// y-axis
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getGrid().setStyle(LineStyle.NONE);
yAxis.getTick().setForeground(BLACK);
yAxis.getTitle().setVisible(false);
// data
for (IChartField field : valFields) {
final IBarSeries bs = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, field.getColumnHeaderText());
bs.setBarColor(new Color(Display.getDefault(), getRC(), getRC(), getRC()));
double[] doubleValues = new double[objects.length];
for (int i = 0; i < objects.length; i++) {
Number num = field.getNumber(objects[i]);
double longVal = num.doubleValue();
doubleValues[i] = longVal;
}
bs.setYSeries(doubleValues);
}
chart.getAxisSet().adjustRange();
return chart;
} catch (PartInitException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
return null;
}
use of org.swtchart.IBarSeries in project linuxtools by eclipse.
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)));
}
}
}
Aggregations