如何绘制jquery条形图

时间:2013-06-10 12:16:28

标签: jquery jsp struts2 charts bar-chart

我有Struts2项目,我在数据库中有值,我成功地从数据库中检索了这些值到jsp表。现在我想在“Jquery条形图”中显示这些值,而不是在表格中显示它们。我在谷歌搜索它,但没有说服任何答案..他们中的一些使用ajax(json)等...是否只有jquery和jsp或java?请指导我或给我任何相关链接。提前致谢。这是我用来从数据库中检索并在表格的jsp页面上显示的代码。 我的动作类如下所示

package com.rajesh.action;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;



public class FebruaryAction {

List abc=  new ArrayList();
List abc1= new ArrayList();
List abc2= new ArrayList();
List abc3= new ArrayList();
List abc4= new ArrayList();
List abc5= new ArrayList();
List abc6= new ArrayList();
List abc7= new ArrayList();






public List getAbc() {
return abc;
}


public void setAbc(List abc) {
this.abc = abc;
}



public List getAbc1() {
return abc1;
}


public void setAbc1(List abc1) {
this.abc1 = abc1;
}



public List getAbc2() {
return abc2;
}


public void setAbc2(List abc2) {
this.abc2 = abc2;
}



public List getAbc3() {
return abc3;
}


public void setAbc3(List abc3) {
this.abc3 = abc3;
}




public List getAbc4() {
return abc4;
}


public void setAbc4(List abc4) {
this.abc4 = abc4;
}


public List getAbc5() {
return abc5;
}


public void setAbc5(List abc5) {
this.abc5 = abc5;
}


public List getAbc6() {
return abc6;
}


public void setAbc6(List abc6) {
this.abc6 = abc6;
}



public List getAbc7() {
return abc7;
}


public void setAbc7(List abc7) {
this.abc7 = abc7;
}


public String execute() throws Exception {

Connection con = GetCon.getCon();
Statement statement = con.createStatement();
ResultSet resultset = statement.executeQuery("SELECT MarketPlace,OrderDate,  ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'AUK' GROUP BY OrderDate,MarketPlace") ;   

while(resultset.next()){
String marketplace = resultset.getString(1);
String orderdate = resultset.getString(2);
Double datamount = resultset.getDouble(3);
Integer count= resultset.getInt(4);
Double result=resultset.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc.add(a);


}

Statement statement1 = con.createStatement();
ResultSet resultset1 = statement1.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'AUS' GROUP BY OrderDate,MarketPlace") ;  

while(resultset1.next()){
String marketplace = resultset1.getString(1);
String orderdate = resultset1.getString(2);
Double datamount = resultset1.getDouble(3);
Integer count= resultset1.getInt(4);
Double result=resultset1.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc1.add(a);
}

Statement statement2 = con.createStatement();
ResultSet resultset2 = statement2.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'ADE' GROUP BY OrderDate,MarketPlace") ;  

while(resultset2.next()){
String marketplace = resultset2.getString(1);
String orderdate = resultset2.getString(2);
Double datamount = resultset2.getDouble(3);
Integer count= resultset2.getInt(4);
Double result=resultset2.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc2.add(a);
}

Statement statement3 = con.createStatement();
ResultSet resultset3 = statement3.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'Ebay' GROUP BY OrderDate,MarketPlace") ; 

while(resultset3.next()){
String marketplace = resultset3.getString(1);
String orderdate = resultset3.getString(2);
Double datamount = resultset3.getDouble(3);
Integer count= resultset3.getInt(4);
Double result=resultset3.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc3.add(a);
}

Statement statement4 = con.createStatement();
ResultSet resultset4 = statement4.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'Play' GROUP BY OrderDate,MarketPlace") ; 

while(resultset4.next()){
String marketplace = resultset4.getString(1);
String orderdate = resultset4.getString(2);
Double datamount = resultset4.getDouble(3);
Integer count= resultset4.getInt(4);
Double result=resultset4.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc4.add(a);
}
Statement statement5 = con.createStatement();
ResultSet resultset5 = statement5.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'Abe' GROUP BY OrderDate,MarketPlace") ;  

while(resultset5.next()){
String marketplace = resultset5.getString(1);
String orderdate = resultset5.getString(2);
Double datamount = resultset5.getDouble(3);
Integer count= resultset5.getInt(4);
Double result=resultset5.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc5.add(a);
}

Statement statement6 = con.createStatement();
ResultSet resultset6 = statement6.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'ACA' GROUP BY OrderDate,MarketPlace") ;  

while(resultset6.next()){
String marketplace = resultset6.getString(1);
String orderdate = resultset6.getString(2);
Double datamount = resultset6.getDouble(3);
Integer count= resultset6.getInt(4);
Double result=resultset6.getDouble(5);


ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc6.add(a);
}



Statement statement8 = con.createStatement();
ResultSet resultset8 = statement8.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >= '2013-02-01' AND OrderDate <= '2013-02-28' AND MarketPlace= 'AFR' GROUP BY OrderDate,MarketPlace") ;  

while(resultset8.next()){
String marketplace = resultset8.getString(1);
String orderdate = resultset8.getString(2);
Double datamount = resultset8.getDouble(3);
Integer count= resultset8.getInt(4);
Double result=resultset8.getDouble(5);

ReportClass a = new ReportClass();
a.setMarketplace(marketplace);
a.setOrderdate(orderdate);
a.setDataamount(datamount);
a.setCount(count);
a.setResult(result);
abc7.add(a);
}
return "success";


}}

我的ReportClass.java

package com.rajesh.action;

public class ReportClass {

String marketplace;
String orderdate;
Double dataamount;
Integer count;
Double result;



public Double getResult() {
return result;
}
public void setResult(Double result) {
this.result = result;
}

public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public String getMarketplace() {
return marketplace;
}
public void setMarketplace(String marketplace) {
this.marketplace = marketplace;
}
public String getOrderdate() {
return orderdate;
}
public void setOrderdate(String orderdate) {
this.orderdate = orderdate;
}
public Double getDataamount() {
return dataamount;
}
public void setDataamount(Double dataamount) {
this.dataamount = dataamount;
}




}

My February.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*,javax.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.rajesh.action.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org     /TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>February</title>
</head>
<body>
<h1>Report for February</h1>





<body>




<table border="1" >
<tr>
<th>Market</th>
<th>Feb-01</th>
<th>Feb-02</th>
<th>Feb-03</th>
<th>Feb-04</th>
<th>Feb-05</th>
<th>Feb-06</th>
<th>Feb-07</th>
<th>Feb-08</th>
<th>Feb-09</th> 
<th>Feb-10</th>
<th>Feb-11</th>
<th>Feb-12</th>
<th>Feb-13</th>
<th>Feb-14</th>
<th>Feb-15</th>
<th>Feb-16</th>
<th>Feb-17</th>
<th>Feb-18</th>
<th>Feb-19</th>
<th>Feb-20</th>
<th>Feb-21</th>
<th>Feb-22</th>
<th>Feb-23</th>
<th>Feb-24</th>
<th>Feb-25</th>
<th>Feb-26</th>
<th>Feb-27</th>
<th>Feb-28</th>
</tr>

<tr>

<td rowspan="3">AUK</td>
<c:forEach items="${abc}" var="item">
<td>${item.count}</td>
</c:forEach>
</tr>
<tr>
<c:forEach items="${abc}" var="item">
<td>${item.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc}" var="item">
<td>${item.result}</td>
</c:forEach>
</tr>

<tr>
<td rowspan="3">AUS</td>
<c:forEach items="${abc1}" var="item1">
<td>${item1.count}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc1}" var="item1">
<td>${item1.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc1}" var="item1">
<td>${item1.result}</td>
</c:forEach>
</tr>

<tr>
<td rowspan="3">ADE</td>
<c:forEach items="${abc2}" var="item2">
<td>${item2.count}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc2}" var="item2">
<td>${item2.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc2}" var="item2">
<td>${item2.result}</td>
</c:forEach>
</tr> 

<tr>
<td rowspan="3">Ebay</td>
<c:forEach items="${abc3}" var="item3">
<td>${item3.count}</td>
</c:forEach>
</tr>


<tr>
<c:forEach items="${abc3}" var="item3">
<td>${item3.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc3}" var="item3">
<td>${item3.result}</td>
</c:forEach>
</tr> 

<tr>
<td rowspan="3">Play</td>
<c:forEach items="${abc4}" var="item4">
<td>${item4.count}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc4}" var="item4">
<td>${item4.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc4}" var="item4">
<td>${item4.result}</td>
</c:forEach>
</tr> 

<tr>
<td rowspan="3">Abe</td>
<c:forEach items="${abc5}" var="item5">
<td>${item5.count}</td>
</c:forEach>
</tr>
<tr>
<c:forEach items="${abc5}" var="item5">
<td>${item5.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc5}" var="item5">
<td>${item5.result}</td> 
</c:forEach>
</tr>
<tr>
<td rowspan="3">ACA</td>
<c:forEach items="${abc6}" var="item6">
<td>${item6.count}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc6}" var="item6">
<td>${item6.dataamount}</td>
</c:forEach>
</tr>
<tr>
<c:forEach items="${abc6}" var="item6">
<td>${item6.result}</td>
</c:forEach>
</tr>
<tr>
<td rowspan="3">AFR</td>
<c:forEach items="${abc7}" var="item7">
<td>${item7.count}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc7}" var="item7">
<td>${item7.dataamount}</td>
</c:forEach>
</tr>

<tr>
<c:forEach items="${abc7}" var="item7">
<td>${item7.result}</td>
</c:forEach>
</tr>

</table>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

Highcharts应该使用jQuery完成所需的所有图表。