src/main/java/org/apache/hadoop/hdfs/server/namenode/queries/Histograms.java
public static String toChartJsJson(
      Map<String, Long> histogram, String title, String ylabel, String xlabel) {
    final long s1 = System.currentTimeMillis();

    final Collection<Long> dataArray = histogram.values();
    Set<String> labels = histogram.keySet();
    Map<String, Object> data = new HashMap<>();
    data.put("labels", labels);
    data.put("xlabel", xlabel);
    data.put("ylabel", ylabel);
    ArrayList<HashMap<String, Object>> datasets = new ArrayList<>();
    HashMap<String, Object> dataset = new HashMap<>();
    dataset.put("label", title);
    dataset.put("data", dataArray);
    datasets.add(dataset);
    data.put("datasets", datasets);

    long e1 = System.currentTimeMillis();
    String gson = new Gson().toJson(data);
    LOG.debug(
        "Time to convert histogram to JSON (for chart.js) of "
            + gson.length()
            + " chars took: "
            + (e1 - s1)
            + " ms.");
    return gson;
  }
/**
   * Converts given histogram along with title, x and y lables to json string for Chart.js.
   *
   * @param histogram data points of histogram
   * @param title title to be used for chart
   * @param ylabel xlabel to be used for chart
   * @param xlabel ylabel to be used for chart
   * @return json string containing data points to be used as input to Chart.js for rendering on
   *     HTML canvas pages
   */
Converts given histogram along with title, x and y lables to json string for Chart.js.
Converts given histogram along with title x and y lables to json string for Chart . js .
public static String toChartJsJson(
      Map<String, Long> histogram, String title, String ylabel, String xlabel) {
    final long s1 = System.currentTimeMillis();
    final Collection<Long> dataArray = histogram.values();
    Set<String> labels = histogram.keySet();
    Map<String, Object> data = new HashMap<>();
    data.put("labels", labels);
    data.put("xlabel", xlabel);
    data.put("ylabel", ylabel);
    ArrayList<HashMap<String, Object>> datasets = new ArrayList<>();
    HashMap<String, Object> dataset = new HashMap<>();
    dataset.put("label", title);
    dataset.put("data", dataArray);
    datasets.add(dataset);
    data.put("datasets", datasets);
    long e1 = System.currentTimeMillis();
    String gson = new Gson().toJson(data);
    LOG.debug(
        "Time to convert histogram to JSON (for chart.js) of "
            + gson.length()
            + " chars took: "
            + (e1 - s1)
            + " ms.");
    return gson;
  }
public static String toChartJsJson ( Map < String , Long > histogram , String title , String ylabel , String xlabel ) { final long s1 = System . currentTimeMillis ( ) ; final Collection < Long > dataArray = histogram . values ( ) ; Set < String > labels = histogram . keySet ( ) ; Map < String , Object > data = new HashMap < > ( ) ; data . put ( "labels" , labels ) ; data . put ( "xlabel" , xlabel ) ; data . put ( "ylabel" , ylabel ) ; ArrayList < HashMap < String , Object > > datasets = new ArrayList < > ( ) ; HashMap < String , Object > dataset = new HashMap < > ( ) ; dataset . put ( "label" , title ) ; dataset . put ( "data" , dataArray ) ; datasets . add ( dataset ) ; data . put ( "datasets" , datasets ) ; long e1 = System . currentTimeMillis ( ) ; String gson = new Gson ( ) . toJson ( data ) ; LOG . debug ( "Time to convert histogram to JSON (for chart.js) of " + gson . length ( ) + " chars took: " + ( e1 - s1 ) + " ms." ) ; return gson ; }
Converts given histogram along with title, x and y lables to json string for Chart.js.
Converts given histogram along with title x and y lables to json string for Chart . js .