如何将hashmap json数据传递给JQPlot?

时间:2013-11-28 11:31:27

标签: jquery json jqplot

我需要将json哈希映射数据传递给jqplot,我不想将json对象转换为数组并传递给jqplot。是否可以将hashmap json传递给jqplot? hashmap包含字符串和值映射。喜欢这个

Map<String, Map<String, Integer>> data;

任何人都可以建议一些想法吗? 提前致谢。

1 个答案:

答案 0 :(得分:0)

看看这个页面 http://www.jqplot.com/tests/data-renderers.php

$(document).ready(function(){
  // Our ajax data renderer which here retrieves a text file.
  // it could contact any source and pull data, however.
  // The options argument isn't used in this renderer.
  var ajaxDataRenderer = function(url, plot, options) {
    var ret = null;
    $.ajax({
      // have to use synchronous here, else the function 
      // will return before the data is fetched
      async: false,
      url: url,
      dataType:"json",
      success: function(data) {
        ret = data;
      }
    });
    return ret;
  };

  // The url for our json data
  var jsonurl = "./jsondata.txt";

  // passing in the url string as the jqPlot data argument is a handy
  // shortcut for our renderer.  You could also have used the
  // "dataRendererOptions" option to pass in the url.
  var plot2 = $.jqplot('chart2', jsonurl,{
    title: "AJAX JSON Data Renderer",
    dataRenderer: ajaxDataRenderer,
    dataRendererOptions: {
      unusedOptionalUrl: jsonurl
    }
  });
});