已经困扰我一个多星期了,求大佬指导,救救孩子吧 前端代码:
series: [
{
name: 'Nightingale Chart',
type: 'pie',
radius: [50, 200],
center: ['50%', '50%'],
roseType: 'area',
left: '30%',
right: '30',
itemStyle: {
borderRadius: 6
},
data:
[
{ value: 40, name: '医疗' },
{ value: 38, name: '交通' },
{ value: 32, name: '就餐' },
{ value: 30, name: '学习' },
{ value: 28, name: '娱乐' },
{ value: 26, name: '其他' }
]
DAO层:
```handlebars
public class ExpenditureRateDao extends BaseDao {
public ExpenditureRateDao(String tableName) {
super(tableName);
}
public List<Map<String,Object>> getExpenditureByUserName(Map<String,String> map){
List<Map<String,Object>> list = null;
List<Map<String,Object>> expenditureTypeList = null;
String sql = "select * from expenditure,expendituretype where userName=? and expenditure.expenditureType=expendituretype.expenditureTypeId";
list=super.executeQuery(sql,map.get("userName"));
ExpenditureTypeDao expenditureTypeDao = new ExpenditureTypeDao("expendituretype");
expenditureTypeList = expenditureTypeDao.getAll();
for (Map<String,Object> map2 :expenditureTypeList){
map2.put("sum",0);
}
// map1是支出数据
// map2是支出类型
for (Map<String,Object> map1 :list){
for (Map<String,Object> map2 :expenditureTypeList){
// 如果取出的支出数据的类型与支出类型一样
if (Integer.parseInt(map1.get("expenditureTypeId").toString()) == Integer.parseInt(map2.get("expenditureTypeId").toString())){
map2.put("sum",Double.parseDouble(map2.get("sum").toString())+Double.parseDouble(map1.get("expenditure").toString()));
break;
}
}
}
return expenditureTypeList;
}
}
server:
public class ExpenditureRateServer {
public List<Map<String,Object>> getExpenditureByUserName(Map<String,String> map){
List<Map<String,Object>> list = null;
ExpenditureRateDao expenditureRateDao = new ExpenditureRateDao("expenditure");
list = expenditureRateDao.getExpenditureByUserName(map);
return list;
}
}
servlet
@WebServlet( "/ExpenditureRateServlet")
public class ExpenditureRateServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<String,String[]> maps = request.getParameterMap();
Map<String,String> map = Util.exchange(maps);
ExpenditureRateServer expenditureRateServer = new ExpenditureRateServer();
List<Map<String,Object>> list = expenditureRateServer.getExpenditureByUserName(map);
String date = JSON.toJSONString(list);
PrintWriter printWriter = response.getWriter();
printWriter.print(date);
printWriter.close();
}
}
|