Search in sources :

Example 1 with DateTickUnit

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;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) DateTickUnit(org.jfree.chart.axis.DateTickUnit) XYPlot(org.jfree.chart.plot.XYPlot) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LocalDate(java.time.LocalDate) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with DateTickUnit

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;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) DateTickUnit(org.jfree.chart.axis.DateTickUnit) XYPlot(org.jfree.chart.plot.XYPlot) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ClusteredXYBarRenderer(org.jfree.chart.renderer.xy.ClusteredXYBarRenderer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart)

Example 3 with DateTickUnit

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;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) DateTickUnit(org.jfree.chart.axis.DateTickUnit) XYPlot(org.jfree.chart.plot.XYPlot) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) SimpleDateFormat(java.text.SimpleDateFormat) LocalDate(java.time.LocalDate) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with DateTickUnit

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;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) DateTickUnit(org.jfree.chart.axis.DateTickUnit) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) ValueMarker(org.jfree.chart.plot.ValueMarker) Marker(org.jfree.chart.plot.Marker) IntervalMarker(org.jfree.chart.plot.IntervalMarker) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Example 5 with DateTickUnit

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);
}
Also used : DateTickUnit(org.jfree.chart.axis.DateTickUnit) DateTickUnitType(org.jfree.chart.axis.DateTickUnitType)

Aggregations

DateTickUnit (org.jfree.chart.axis.DateTickUnit)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JFreeChart (org.jfree.chart.JFreeChart)4 DateAxis (org.jfree.chart.axis.DateAxis)4 XYPlot (org.jfree.chart.plot.XYPlot)4 DateFormat (java.text.DateFormat)3 LocalDate (java.time.LocalDate)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)3 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)3 Date (java.util.Date)2 XYBarRenderer (org.jfree.chart.renderer.xy.XYBarRenderer)2 BasicStroke (java.awt.BasicStroke)1 DateTickUnitType (org.jfree.chart.axis.DateTickUnitType)1 IntervalMarker (org.jfree.chart.plot.IntervalMarker)1 Marker (org.jfree.chart.plot.Marker)1 ValueMarker (org.jfree.chart.plot.ValueMarker)1 ClusteredXYBarRenderer (org.jfree.chart.renderer.xy.ClusteredXYBarRenderer)1 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)1