package com.chart; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import com.chart.vo.ChartData; import com.chart.vo.PieChartData; import com.chart.vo.QueryVo; import com.formaction.vo.RowSet; public class BarChart extends Chart{ private String propertyName; private QueryVo qv = null; public BarChart(QueryVo qv) { this.qv = qv; this.propertyName = qv.getFieldXAxis(); } @SuppressWarnings({ "rawtypes" }) @Override public List getJsonData() { List chartData = new ArrayList(); List datas = super.queryData(qv); Map temp = new HashMap(); if (null == datas || datas.size() == 0) { return chartData; } RowSet rowSet = datas.get(0); List rows = rowSet.getRows(); for (Map m : rows) { for (Object key : m.keySet()) { String k = String.valueOf(key); String v = String.valueOf(m.get(k)); // String constantName = qv.getTranferConstant().get(v); if (propertyName.equalsIgnoreCase(String.valueOf(k))) {// 取常量值 if (null == temp.get(v)) { temp.put(v, 1); } else { temp.put(v, temp.get(v) + 1); } } } } Object[] key = temp.keySet().toArray(); Arrays.sort(key); for (int i = 0; i < key.length; i++) { PieChartData cd = new PieChartData(); cd.setName(qv.getTranferConstant().get(key[i].toString())); cd.setValue(temp.get(key[i])); chartData.add(cd); } return chartData; } }