Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC + JqPlot Chart Data Retreiving error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC + JqPlot Chart Data Retreiving error

    My Spring Controller class looks like this

    Code:
    	@SuppressWarnings("rawtypes")
    	@RequestMapping(value = "/cityGridView", method = RequestMethod.GET)
    	public @ResponseBody
    	Object[] showLineChart(Map<String, Object> map, HttpServletRequest request,
    			HttpServletResponse response) {
    		List<MapTable> list = contactService.fin();
    		Object[] rows = new Object[list.size()];
    		int i = 0;
    		for (MapTable table : list) {
    			Object[] temp = new Object[2];
    			temp[0] = table.getSRDate();
    			temp[1] = table.getNumberOfSR();
    			rows[i] = temp;
    			i++;
    		}
    		Object[] object = new Object[1];
    		object[0] = rows;
    		return object;
    	}
    In my jsp i handle response like this.

    Code:
        
    	<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 Array

    Code:
    [["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

    Code:
        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


    Code:
        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;
        	}

    Line Chart X & Y Axis & data Line also loaded now
    thank all........... :-)
    Last edited by priyanka_hdp; Oct 23rd, 2012, 05:20 AM. Reason: edited
Working...
X