Created
October 24, 2012 02:20
-
-
Save priyankahdp/3943339 to your computer and use it in GitHub Desktop.
JqPlot charts with Spring MVC on Maven
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:aop="http://www.springframework.org/schema/aop" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:jee="http://www.springframework.org/schema/jee" | |
xmlns:lang="http://www.springframework.org/schema/lang" | |
xmlns:p="http://www.springframework.org/schema/p" | |
xmlns:tx="http://www.springframework.org/schema/tx" | |
xmlns:util="http://www.springframework.org/schema/util" | |
xmlns:mvc="http://www.springframework.org/schema/mvc" | |
xsi:schemaLocation= | |
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | |
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd | |
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd | |
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd | |
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd | |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd | |
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> | |
<!-- Json Viewer --> | |
<mvc:annotation-driven /> | |
<context:annotation-config /> | |
<context:component-scan base-package="com.priyan.contact" /> | |
<!-- Configure the Message properties --> | |
<bean id="messageSource" | |
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> | |
<property name="basename" value="classpath:messages" /> | |
<property name="defaultEncoding" value="UTF-8" /> | |
</bean> | |
<!-- Configure the JDBC properties --> | |
<bean id="propertyConfigurer" | |
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" | |
p:location="/WEB-INF/jdbc.properties" /> | |
<!-- Configure the Datasource properties | |
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" | |
destroy-method="close" p:driverClassName="${jdbc.driverClassName}" | |
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> | |
--> | |
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler"> | |
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/> | |
</bean> | |
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/> | |
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> | |
<property name="dataSource" ref="dataSource"/> | |
</bean> | |
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> | |
<property name="driverClassName" value="${jdbc.driverClassName}"/> | |
<property name="url" value="${jdbc.databaseurl}"/> | |
<property name="username" value="${jdbc.username}"/> | |
<property name="password" value="${jdbc.password}"/> | |
</bean> | |
<bean id="contactDAO" class="com.priyan.contact.dao.ContactDAOImpl"> | |
<property name="dataSource" ref="dataSource"/> | |
</bean> | |
<!-- Initialize Session --> | |
<bean id="sessionFactory" | |
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> | |
<property name="dataSource" ref="dataSource" /> | |
<property name="configLocation"> | |
<value>classpath:hibernate.cfg.xml</value> | |
</property> | |
<property name="configurationClass"> | |
<value>org.hibernate.cfg.AnnotationConfiguration</value> | |
</property> | |
<property name="hibernateProperties"> | |
<props> | |
<prop key="hibernate.dialect">${jdbc.dialect}</prop> | |
<prop key="hibernate.show_sql">true</prop> | |
<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> --> | |
</props> | |
</property> | |
</bean> | |
<!-- Add Transaction Handling --> | |
<tx:annotation-driven /> | |
<bean id="transactionManager" | |
class="org.springframework.orm.hibernate3.HibernateTransactionManager"> | |
<property name="sessionFactory" ref="sessionFactory" /> | |
</bean> | |
<!-- TILES --> | |
<bean id="viewResolver" | |
class="org.springframework.web.servlet.view.UrlBasedViewResolver"> | |
<property name="viewClass"> | |
<value> | |
org.springframework.web.servlet.view.tiles2.TilesView | |
</value> | |
</property> | |
</bean> | |
<!-- Add Tiles Support--> | |
<bean id="tilesConfigurer" | |
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> | |
<property name="definitions"> | |
<list> | |
<value>/WEB-INF/tiles.xml</value> | |
</list> | |
</property> | |
</bean> | |
<!-- Add Ajax Capability--> | |
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/> | |
<bean id="ajaxViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver"> | |
<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/> | |
</bean> | |
<!-- Add Validation Handling --> | |
<bean id="contactValidator" class="com.priyan.contact.validator.ContactValidator"/> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/JavaScript"> | |
<!-- | |
var sURL = unescape(window.location.pathname); | |
function doLoad() { | |
setTimeout("refresh()", 3600 * 1000); | |
} | |
function refresh() { | |
window.location.href = sURL; | |
} | |
// --> | |
</script> | |
</head> | |
<body onload="doLoad()"> | |
<h1 style="color: white;">cityGridView.html</h1> | |
<div id="chart1" style="width: 1000px;height: 400px" ></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; | |
//alert(data); | |
} | |
}); | |
return ret; | |
}; | |
var jsonurl = 'cityGridView.html'; | |
var today = new Date(); | |
var mindate=new Date(today.getTime() - 14 * 24 * 60 * 60 * 1000); | |
//above mindate used for get last 14days | |
var plot1 = $.jqplot('chart1', jsonurl, { | |
title:'SR Complaint count for last 14 Days', | |
dataRenderer: ajaxDataRenderer, | |
dataRendererOptions: { | |
unusedOptionalUrl: jsonurl | |
}, | |
axesDefaults: { | |
tickRenderer: $.jqplot.CanvasAxisTickRenderer , | |
tickOptions: { | |
fontFamily: 'courier', | |
fontSize: '12pt', | |
angle: -30 | |
} | |
}, | |
axes:{ | |
xaxis:{ | |
label: "Dates", | |
labelRenderer: $.jqplot.CanvasAxisLabelRenderer, | |
labelOptions: { | |
fontFamily: 'Georgia, Serif', | |
fontSize: '16pt' | |
}, | |
numberTicks : 15, | |
//min: '2012-10-10', | |
min:mindate, | |
max: today, | |
renderer:$.jqplot.DateAxisRenderer, | |
rendererOptions:{tickRenderer:$.jqplot.CanvasAxisTickRenderer}, | |
tickInterval:'2 day', | |
tickOptions:{ | |
formatString:'%#m-%#d' | |
} | |
}, | |
yaxis:{ | |
label: "Count", | |
labelRenderer: $.jqplot.CanvasAxisLabelRenderer, | |
labelOptions: { | |
fontFamily: 'Georgia, Serif', | |
fontSize: '16pt' | |
}, | |
numberTicks:10, | |
tickOptions:{ | |
formatString:'%d', | |
angle: 0 | |
}, | |
min:0, | |
max:200 | |
} | |
}, | |
seriesDefaults: { | |
label: 'Comaplints', | |
color:'blue', | |
showMarker:false, | |
pointLabels: { show:true }, | |
markerOptions: { style:'dimaond'}, | |
lineWidth: 3.5, | |
}, | |
legend: { | |
show: true, | |
location: 'ne', | |
xoffset: 10, | |
yoffset: 12, | |
}, | |
highlighter: { | |
show: true, | |
sizeAdjust: 7.5 | |
}, | |
cursor: { | |
show: true, | |
tooltipLocation:'sw' | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Method Only | |
@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; | |
} | |
/** | |
Special thanks for | |
nickdos @ Stackoverflow forum, | |
Chathura @ Dialog | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -14 " + | |
"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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.priyan.contact.form; | |
import java.util.Date; | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment