12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<ChartData> getJsonData() {
- List<ChartData> chartData = new ArrayList<ChartData>();
- List<RowSet> datas = super.queryData(qv);
- Map<String, Integer> temp = new HashMap<String, Integer>();
- if (null == datas || datas.size() == 0) {
- return chartData;
- }
- RowSet rowSet = datas.get(0);
- List<Map> 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;
- }
- }
|