示例#1
0
  byte[] graph(Range range, int width, int height, boolean maxHidden) throws IOException {
    // static init of the AppContext ClassLoader
    AppContextClassLoaderLeakPrevention.dummy();

    try {
      // Rq : il pourrait être envisagé de récupérer les données dans les fichiers rrd ou autre
      // stockage
      // puis de faire des courbes en sparklines html (sauvegardées dans la page html)
      // ou avec http://code.google.com/apis/chart/types.html#sparkline ou jfreechart

      // create common part of graph definition
      final RrdGraphDef graphDef = new RrdGraphDef();
      if (Locale.CHINESE.getLanguage().equals(I18N.getResourceBundle().getLocale().getLanguage())) {
        graphDef.setSmallFont(new Font(Font.MONOSPACED, Font.PLAIN, 10));
        graphDef.setLargeFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
      }

      initGraphSource(graphDef, height, maxHidden);

      initGraphPeriodAndSize(range, width, height, graphDef);

      graphDef.setImageFormat("png");
      graphDef.setFilename("-");
      // il faut utiliser le pool pour les performances
      // et pour éviter des erreurs d'accès concurrents sur les fichiers
      // entre différentes générations de graphs et aussi avec l'écriture des données
      graphDef.setPoolUsed(true);
      return new RrdGraph(graphDef).getRrdGraphInfo().getBytes();
    } catch (final RrdException e) {
      throw createIOException(e);
    }
  }