Commit aaf38883 authored by dkasliwal's avatar dkasliwal

Add new method for Bubble Chart using chart.js API


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@104442 ce508802-f39f-4f6c-b175-0d175dae99d5
parent cbe6ac01
......@@ -1633,4 +1633,96 @@ public class ChartCreator
return graphJson;
}
/**End of Gantt chart method by swati dated: 05 April 2015 **/
/*Add Code New method for getBubbleChart using chart.js API on date 16-01-2017 */
public static JSONObject getBubbleChart(ArrayList<ArrayList<String>> graphDtlList, JSONObject jsonObjGraph, String dataSource)
{
JSONObject bubbleChartJson = new JSONObject();
JSONObject jsonObjFrGraph = (JSONObject) jsonObjGraph.get(dataSource);
ArrayList<String> dataList = new ArrayList<String>();
ArrayList<String> labelList = new ArrayList<String>();
ArrayList<LinkedHashMap<JSONValue, JSONValue>> allDataList = null;
ArrayList<LinkedHashMap<JSONValue, String>> dataListMap = null;
LinkedHashMap<JSONValue, String> dataMap = null;
LinkedHashMap<JSONValue, JSONValue> datasetMap = null;
JSONObject fetchRowWiseVal = null;
String data = "";
for (int i = 0; i < graphDtlList.size(); i++)
{
if (i == 7)
{
labelList = (ArrayList<String>) graphDtlList.get(i);
}
if (i == 8)
{
dataList = (ArrayList<String>) graphDtlList.get(i);
}
}
dataListMap = new ArrayList<LinkedHashMap<JSONValue,String>>();
allDataList = new ArrayList<LinkedHashMap<JSONValue,JSONValue>>();
CommonUtils.printOnConsole("labelList :"+labelList);
CommonUtils.printOnConsole("dataList :"+dataList);
for (int jsnCnt = 0; jsnCnt < jsonObjFrGraph.size(); jsnCnt++)
{
dataMap = new LinkedHashMap<JSONValue, String>();
datasetMap = new LinkedHashMap<JSONValue, JSONValue>();
dataListMap = new ArrayList<LinkedHashMap<JSONValue,String>>();
fetchRowWiseVal = (JSONObject) jsonObjFrGraph.get(String.valueOf(jsnCnt));
for (String lblName : labelList)
{
CommonUtils.printOnConsole("lblName :"+lblName);
data = fetchRowWiseVal.get(lblName).toString().replace('"', ' ');
if (data.trim().length() != 0)
{
datasetMap.put(new JSONString("label"),fetchRowWiseVal.get(lblName));
int r = (int)(Math.random() * 255);
int g = (int)(Math.random() * 255);
int b = (int)(Math.random() * 255);
String rgba = "rgba("+r+","+g+","+b+",0.9)";
String rgb = "rgb("+r+","+g+","+b+")";
datasetMap.put(new JSONString("backgroundColor"),new JSONString(rgba));
datasetMap.put(new JSONString("borderColor"),new JSONString(rgb));
datasetMap.put(new JSONString("hoverBackgroundColor"),new JSONString(rgb));
datasetMap.put(new JSONString("borderWidth"),new JSONString("1"));
}
}
//for (String idName : dataList)
for (int i = 0; i < dataList.size(); i++)
{
CommonUtils.printOnConsole("idName :"+dataList.get(i));
data = fetchRowWiseVal.get(dataList.get(i)).toString().replace('"', ' ');
if (data.trim().length() != 0)
{
if(i == 0)
{
dataMap.put(new JSONString("x"),fetchRowWiseVal.get(dataList.get(i)).toString().replace('"', ' '));
}
if(i == 1)
{
dataMap.put(new JSONString("y"),fetchRowWiseVal.get(dataList.get(i)).toString().replace('"', ' '));
}
if(i == 2)
{
dataMap.put(new JSONString("r"),fetchRowWiseVal.get(dataList.get(i)).toString().replace('"', ' '));
}
}
}
dataListMap.add(dataMap);
datasetMap.put(new JSONString("data"), JSONParser.parseStrict(dataListMap.toString().replace('=', ':')));
allDataList.add(datasetMap);
}
bubbleChartJson.put("datasets", JSONParser.parseStrict(allDataList.toString().replace('=', ':')));
return bubbleChartJson;
}
/*End Code New method for getBubbleChart using chart.js API on date 16-01-2017 */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment