问题
My Spring Controller class looks like this
@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;
}
In my jsp i handle response like this. (seems issue in here ??)
<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>
My JSON like this
[["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]]
Here shows my MapTable Class
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;
}
}
contactService.fin(); Method called to Service Classes & finally it in DAO classes. Data also correctly come like above i mentioned array.here is my DAO class
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;
}
回答1:
Your expected vs actual JSON data are different in a couple of ways and you have not stated which differences matter. But I'll tackle the "rows":
bit first as it represents a JSON structural difference (as opposed to data value differences).
Your actual JSON output contains the "rows":
property because you have returned a Grid
object from your controller - which had a field called rows
populated with your list of lists. If you simply want your JSON to contain the list of lists, then return that from your controller: return rows
.
Your date format is also different, so I would look at the getter method for your MapTable .getSRDate()
as a first step - there is not enough info/code in your question to address this directly.
来源:https://stackoverflow.com/questions/13000541/jqplot-line-chart-with-json-array-chart-not-loaded