@Override
  protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    UsageStatisticsService svc = Context.getService(UsageStatisticsService.class);
    List<Object[]> stats = svc.getDateRangeStats(null, null, null);

    String xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.date");
    String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records");
    String seriesUsages = ContextProvider.getMessage("usagestatistics.results.views");
    String seriesEncounters = ContextProvider.getMessage("usagestatistics.results.encounters");
    String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates");

    // Get minimum date value in returned statistics
    Date minDate = (stats.size() > 0) ? (Date) (stats.get(0)[0]) : getFromDate();
    if (minDate.getTime() > getFromDate().getTime()) // Min date must be at least a week ago
    minDate = getFromDate();
    // Maximum date defaults to today
    Date maxDate = (getUntilDate() != null) ? getUntilDate() : new Date();

    // Build a zeroized dataset of all dates in range
    TimeTableXYDataset dataset = new TimeTableXYDataset();
    Calendar cal = new GregorianCalendar();
    cal.setTime(minDate);
    while (cal.getTime().getTime() <= maxDate.getTime()) {
      Date day = cal.getTime();
      dataset.add(new Day(day), 0, seriesUsages, false);
      dataset.add(new Day(day), 0, seriesEncounters, false);
      dataset.add(new Day(day), 0, seriesUpdates, false);
      cal.add(Calendar.DATE, 1);
    }

    // Update the dates for which we have statistics
    for (Object[] row : stats) {
      Date date = (Date) row[0];
      int usages = ((Number) row[1]).intValue();
      int encounters = ((Number) row[2]).intValue();
      int updates = ((Number) row[3]).intValue();
      dataset.add(new Day(date), usages, seriesUsages, false);
      dataset.add(new Day(date), encounters, seriesEncounters, false);
      dataset.add(new Day(date), updates, seriesUpdates, false);
    }
    dataset.setDomainIsPointsInTime(true);

    JFreeChart chart =
        ChartFactory.createXYLineChart(
            null, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, false, false);
    DateAxis xAxis = new DateAxis(xAxisLabel);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainAxis(xAxis);

    return chart;
  }
  @Override
  protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    // Get the time function
    String func = ServletRequestUtils.getStringParameter(request, "func", "hour");

    UsageStatisticsService svc = Context.getService(UsageStatisticsService.class);

    int[][] timeStats = new int[0][0];
    String xAxisLabel = null;
    String[] categories = null;
    if (func.equals("hour")) {
      timeStats = svc.getHourStats(getFromDate(), getUntilInclusiveDate(), getLocation());
      xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.hour");
    } else if (func.equals("dayofweek")) {
      timeStats = svc.getDayOfWeekStats(getFromDate(), getUntilInclusiveDate(), getLocation());
      xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.day");
      categories = ContextProvider.getMessage("usagestatistics.chart.dayNames").split("\\|");
    }

    String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records");
    String seriesView = ContextProvider.getMessage("usagestatistics.results.views");
    String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int c = 0; c < timeStats.length; c++) {
      dataset.addValue(
          timeStats[c][0], seriesView, (categories != null) ? categories[c] : (c + ""));
      dataset.addValue(
          timeStats[c][1], seriesUpdates, (categories != null) ? categories[c] : (c + ""));
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            null, // Chart title
            xAxisLabel, // Domain axis label
            yAxisLabel, // Range axis label
            dataset, // Data
            PlotOrientation.VERTICAL, // Orientation
            true, // Include legend
            false, // Tooltips?
            false // URLs?
            );

    return chart;
  }