use of name.abuchen.portfolio.ui.util.chart.PlainChart in project portfolio by buchen.
the class AbstractChartTab method createControl.
@Override
public Control createControl(Composite parent) {
resources = new LocalResourceManager(JFaceResources.getResources(), parent);
chart = new PlainChart(parent, SWT.NONE);
// $NON-NLS-1$
chart.setData(UIConstants.CSS.CLASS_NAME, "chart");
chart.getTitle().setVisible(false);
chart.getLegend().setPosition(SWT.BOTTOM);
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.getTitle().setVisible(false);
xAxis.getTitle().setText(Messages.ColumnMonth);
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getTitle().setVisible(false);
yAxis.setPosition(Position.Secondary);
xAxis.enableCategory(true);
// format symbols returns 13 values as some calendars have 13 months
xAxis.setCategorySeries(Arrays.copyOfRange(new DateFormatSymbols().getMonths(), 0, 12));
createSeries();
chart.getAxisSet().adjustRange();
// if max/min value of range is more than 1000, formatting is #.#k
Range r = yAxis.getRange();
if (r.lower < -1000.0 || r.upper > 1000.0) {
yAxis.getTick().setFormat(new ThousandsNumberFormat());
}
attachTooltipTo(chart);
model.addUpdateListener(this::updateChart);
return chart;
}
use of name.abuchen.portfolio.ui.util.chart.PlainChart in project portfolio by buchen.
the class ActivityWidget method createControl.
@Override
public Composite createControl(Composite parent, DashboardResources resources) {
Composite container = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(container);
container.setBackground(parent.getBackground());
title = new Label(container, SWT.NONE);
title.setBackground(container.getBackground());
title.setText(TextUtil.tooltip(getWidget().getLabel()));
GridDataFactory.fillDefaults().grab(true, false).applyTo(title);
chart = new PlainChart(container, SWT.NONE);
// $NON-NLS-1$
chart.setData(UIConstants.CSS.CLASS_NAME, "chart");
getDashboardData().getStylingEngine().style(chart);
chart.setBackground(container.getBackground());
chart.getTitle().setVisible(false);
chart.getTitle().setText(title.getText());
chart.getLegend().setVisible(false);
toolTip = new TimelineChartToolTip(chart);
toolTip.enableCategory(true);
toolTip.reverseLabels(true);
// $NON-NLS-1$
toolTip.setDefaultValueFormat(new DecimalFormat("#"));
toolTip.setXAxisFormat(obj -> {
Integer index = (Integer) obj;
@SuppressWarnings("unchecked") List<YearMonth> yearMonths = (List<YearMonth>) chart.getData();
return yearMonths.get(index).toString();
});
int yHint = get(ChartHeightConfig.class).getPixel();
GridDataFactory.fillDefaults().hint(SWT.DEFAULT, yHint).grab(true, false).applyTo(chart);
// configure axis
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.getTick().setVisible(true);
xAxis.getTitle().setVisible(false);
xAxis.getTitle().setText(Messages.ColumnMonth);
xAxis.getGrid().setStyle(LineStyle.NONE);
xAxis.enableCategory(true);
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getTitle().setVisible(false);
yAxis.setPosition(Position.Secondary);
chart.getPlotArea().addTraverseListener(event -> event.doit = true);
((IPlotArea) chart.getPlotArea()).addCustomPaintListener(new TimeGridPaintListener(chart));
container.layout();
return container;
}
Aggregations