0

我的 Spring Controller 类看起来像这样

@SuppressWarnings("rawtypes")
    @RequestMapping(value = "/cityGridView", method = RequestMethod.GET)
    public @ResponseBody
    List showLineChart(Map<String, Object> map,
            HttpServletRequest request, HttpServletResponse response) {
        List<Object> rows = new ArrayList<Object>();
        List<MapTable> list = contactService.fin();
        for (MapTable table : list) {
            List<Object> dataRow = new ArrayList<Object>(1);
            dataRow.add(table.getSRDate());
            dataRow.add(table.getNumberOfSR());
            rows.add(dataRow);
        }
        return rows;
    }      

在我的jsp中,我处理这样的响应。(这里似乎有问题??)

<div id="chart1" style="width: 800px;height: 500px" ></div>
    <script type="text/javascript">
    $(document).ready(function(){
          var ajaxDataRenderer = function(url, plot, options) {
            var ret = null;
            $.ajax({
              async: false,
              url: url,
              dataType:"json",
              success: function(data) {
                ret = data;
              }
            });
            return ret;         
          };

    var jsonurl = 'cityGridView.html';

    var today = new Date(); 

    var plot1 = $.jqplot('chart1', jsonurl, {
          title:'Data Point Highlighting',
          dataRenderer: ajaxDataRenderer,
          dataRendererOptions: {
              unusedOptionalUrl: jsonurl
              },
          axes:{
            xaxis:{
                label: "SR_DATES",
                'numberTicks' : 7,
                min: '2012-10-01',
                max: '2012-10-07',
                renderer:$.jqplot.DateAxisRenderer,
                rendererOptions:{tickRenderer:$.jqplot.CanvasAxisTickRenderer},
                tickInterval:'1 day', 
                tickOptions:{
                    formatString:'%Y-%#m-%#d'
                    }
            },
            yaxis:{
                label: "SR COUNT",
                tickOptions:{
                    formatString:'%d'
                    },
                min:10,
                max:30
            }
          },
          highlighter: {
            show: true,
            sizeAdjust: 7.5
          },
          cursor: {
            show: true
          }
      });
    });

    </script>
  • 我的 JSON 是这样的

    [["2012-10-01",15.0],["2012-10-02",20.0],["2012-10-03",25.0],["2012-10-04",18.0],[ "2012-10-05",22.0],["2012-10-06",24.0]]

这里显示了我的 MapTable 类

public class MapTable {

    private Date SRDate;
    private int numberOfSR;

    public Date getSRDate() {
        return SRDate;
    }

    public void setSRDate(Date sRDate) {
        SRDate = sRDate;
    }

    public int getNumberOfSR() {
        return numberOfSR;
    }

    public void setNumberOfSR(int numberOfSR) {
        this.numberOfSR = numberOfSR;
    }
}

联系服务.fin(); 调用服务类的方法,最后在 DAO 类中调用它。数据也正确地像上面提到的数组一样。这是我的 DAO 类

public List<MapTable> fin(){
        @SuppressWarnings("unchecked")
        List<MapTable> dashboardBeanList = jdbcTemplate
                    .query("select trunc(ASSIGNED_datetime) as SR_DATE, count(*) as COUNT " +
                            "from sbl_service_request_v " +
                            "where SR_TYPE ='Complaint' " +
                            "and DATE_COMMITED  is not null " +
                            "and ASSIGNED_DIVISION  in ('CSO','IT_IVR') " +
                            "and trunc(ASSIGNED_datetime) >= sysdate -30 " +
                            "group by  trunc(ASSIGNED_datetime) " +
                            "order by trunc(ASSIGNED_datetime)",
                                            new Object[] {},
                                new RowMapper() {
                                      public MapTable mapRow(ResultSet rs, int rowNum)
                                                  throws SQLException {
                                          MapTable dashboardBean=new MapTable();
                                          dashboardBean.setSRDate(rs.getDate("SR_DATE"));
                                          dashboardBean.setNumberOfSR(rs.getInt("COUNT"));
                                          return dashboardBean;
                                      }
                                });
        return dashboardBeanList;
    }
4

1 回答 1

0

您的预期与实际 JSON 数据在几个方面有所不同,并且您没有说明哪些差异很重要。但我将"rows":首先解决这个问题,因为它代表 JSON 结构差异(而不是数据值差异)。

您的实际 JSON 输出包含该"rows":属性,因为您Grid从控制器返回了一个对象 - 该对象有一个名为rows填充列表列表的字段。如果您只是希望您的 JSON 包含列表列表,请从您的控制器返回它:return rows

你的日期格式也不同,所以我会先看看你的 getter 方法MapTable .getSRDate()——你的问题中没有足够的信息/代码来直接解决这个问题。

于 2012-10-21T23:59:44.687 回答