use of org.jfree.chart.axis.DateTickUnit in project jgnash by ccavanaugh.
the class MonthlyAccountBalanceChart method createVerticalXYBarChart.
private JFreeChart createVerticalXYBarChart(Account a) {
DateFormat df = new SimpleDateFormat("MM/yy");
TimeSeriesCollection data = createTimeSeriesCollection(a);
DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
// if (a.getTransactionCount() > 0) {
Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
dateAxis.setRange(start, end);
// }
NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance"));
StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance());
XYBarRenderer renderer = new XYBarRenderer(0.2);
renderer.setBaseToolTipGenerator(tooltipGenerator);
XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
String title = rb.getString("Title.AccountBalance") + " - " + a.getPathName();
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.axis.DateTickUnit in project jgnash by ccavanaugh.
the class MonthlyAccountBalanceChartCompare method createVerticalXYBarChart.
private JFreeChart createVerticalXYBarChart(final Account a, final Account a2) {
DateFormat df = new SimpleDateFormat("MM/yy");
TimeSeriesCollection data = createTimeSeriesCollection(a, a2);
DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
// if (a.getTransactionCount() > 0) {
Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
dateAxis.setRange(start, end);
// }
NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance") + "-" + a.getCurrencyNode().getSymbol());
StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance());
ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(0.2, false);
renderer.setBaseToolTipGenerator(tooltipGenerator);
XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
String title;
if (jcb_compare.isSelected()) {
title = a.getPathName() + " vs " + a2.getPathName();
} else {
title = rb.getString("Title.AccountBalance") + " - " + a.getPathName();
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.axis.DateTickUnit in project jgnash by ccavanaugh.
the class RunningAccountBalanceChart method createVerticalXYBarChart.
private JFreeChart createVerticalXYBarChart(Account a) {
DateFormat df = new SimpleDateFormat("MM/yy");
TimeSeriesCollection data = createTimeSeriesCollection(a);
DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate());
LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
dateAxis.setRange(DateUtils.asDate(start), DateUtils.asDate(end));
NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance"));
StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance());
XYBarRenderer renderer = new XYBarRenderer(0.2);
renderer.setBaseToolTipGenerator(tooltipGenerator);
XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
String title = rb.getString("Title.EndMonthBalance") + " - " + a.getPathName();
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.axis.DateTickUnit in project pinot by linkedin.
the class AnomalyGraphGenerator method createChart.
/**
* Creates a chart containing the current/baseline data (in that order) as well as markers for
* each anomaly interval. timeGranularity and windowMillis are used to determine the date format
* and spacing for tick marks on the domain (x) axis.
*/
public JFreeChart createChart(final XYDataset dataset, final String metric, final TimeGranularity timeGranularity, final long windowMillis, final Map<RawAnomalyResultDTO, String> anomaliesWithLabels) {
// create the chart...
final JFreeChart chart = // no chart title for email
ChartFactory.createTimeSeriesChart(// no chart title for email
null, // x axis label
"Date (" + DEFAULT_TIME_ZONE.getID() + ")", // y axis label
metric, // data
dataset, // include legend
true, // tooltips - n/a if the chart will be saved as an img
false, // urls - n/a if the chart will be saved as an img
false);
// get a reference to the plot for further customisation...
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
// dashboard webapp currently uses solid blue for current and dashed blue for baseline
// (5/2/2016)
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesShapesVisible(0, false);
renderer.setSeriesShapesVisible(1, false);
renderer.setSeriesPaint(0, Color.BLUE);
renderer.setSeriesPaint(1, Color.BLUE);
// http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
// set baseline to be dashed
renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
plot.setRenderer(renderer);
DateAxis axis = (DateAxis) plot.getDomainAxis();
DateTickUnit dateTickUnit = getDateTickUnit(timeGranularity, windowMillis);
SimpleDateFormat dateFormat = getDateFormat(timeGranularity);
axis.setDateFormatOverride(dateFormat);
axis.setTickUnit(dateTickUnit);
axis.setVerticalTickLabels(true);
List<Marker> anomalyIntervals = getAnomalyIntervals(anomaliesWithLabels);
for (Marker marker : anomalyIntervals) {
plot.addDomainMarker(marker);
}
return chart;
}
use of org.jfree.chart.axis.DateTickUnit in project pinot by linkedin.
the class AnomalyGraphGenerator method getDateTickUnit.
private DateTickUnit getDateTickUnit(final TimeGranularity timeGranularity, final long windowMillis) {
long windowBuckets = timeGranularity.convertToUnit(windowMillis);
int tickSize = (int) Math.ceil(windowBuckets / (double) NUM_X_TICKS);
DateTickUnitType unitType;
switch(timeGranularity.getUnit()) {
case DAYS:
unitType = DateTickUnitType.DAY;
break;
case HOURS:
unitType = DateTickUnitType.HOUR;
break;
case MILLISECONDS:
unitType = DateTickUnitType.MILLISECOND;
break;
case MINUTES:
unitType = DateTickUnitType.MINUTE;
break;
case SECONDS:
unitType = DateTickUnitType.SECOND;
break;
default:
throw new IllegalArgumentException("Unsupported time unit granularity: " + timeGranularity.getUnit());
}
return new DateTickUnit(unitType, tickSize);
}
Aggregations