74bd7e94f6163b80d52cdb302f08eb278cba8585.svn-base 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.chart;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import com.chart.vo.ChartData;
  8. import com.chart.vo.PieChartData;
  9. import com.chart.vo.QueryVo;
  10. import com.formaction.vo.RowSet;
  11. public class BarChart extends Chart{
  12. private String propertyName;
  13. private QueryVo qv = null;
  14. public BarChart(QueryVo qv) {
  15. this.qv = qv;
  16. this.propertyName = qv.getFieldXAxis();
  17. }
  18. @SuppressWarnings({ "rawtypes" })
  19. @Override
  20. public List<ChartData> getJsonData() {
  21. List<ChartData> chartData = new ArrayList<ChartData>();
  22. List<RowSet> datas = super.queryData(qv);
  23. Map<String, Integer> temp = new HashMap<String, Integer>();
  24. if (null == datas || datas.size() == 0) {
  25. return chartData;
  26. }
  27. RowSet rowSet = datas.get(0);
  28. List<Map> rows = rowSet.getRows();
  29. for (Map m : rows) {
  30. for (Object key : m.keySet()) {
  31. String k = String.valueOf(key);
  32. String v = String.valueOf(m.get(k));
  33. // String constantName = qv.getTranferConstant().get(v);
  34. if (propertyName.equalsIgnoreCase(String.valueOf(k))) {// 取常量值
  35. if (null == temp.get(v)) {
  36. temp.put(v, 1);
  37. } else {
  38. temp.put(v, temp.get(v) + 1);
  39. }
  40. }
  41. }
  42. }
  43. Object[] key = temp.keySet().toArray();
  44. Arrays.sort(key);
  45. for (int i = 0; i < key.length; i++) {
  46. PieChartData cd = new PieChartData();
  47. cd.setName(qv.getTranferConstant().get(key[i].toString()));
  48. cd.setValue(temp.get(key[i]));
  49. chartData.add(cd);
  50. }
  51. return chartData;
  52. }
  53. }