Hi,
I am trying to draw google chart using server side populated data.To
generate data i have a REST service class that responsible for sending json
obj with values.I use google
data source library to populate google chart supported json obj.But problem
was that when i insert data table column value type as DateTime it wont
populate rows in json.But i move it to like following code snippet and its
populate valid json but when visualizing on charts it gave me column is not
Date.
*Rest service class Java*
@Produces(MediaType.APPLICATION_JSON)
public String getTestResultAsGoogleChartSupport(
@QueryParam("items") int result) {
final int resultCount = result;
final DataTable data = new DataTable();
ArrayList<ColumnDescription> cl = new ArrayList<ColumnDescription>();
cl.add(new ColumnDescription("Test Plan", ValueType.TEXT, "Test Plan"));
cl.add(new ColumnDescription("Test Script", ValueType.TEXT,"Test Script"));
cl.add(new ColumnDescription("Status", ValueType.TEXT, "Status"));
cl.add(new ColumnDescription("Type", ValueType.TEXT, "Type"));
cl.add(new ColumnDescription("ENV", ValueType.TEXT, "ENV"));
cl.add(new ColumnDescription("Build No", ValueType.TEXT, "Build No"));
cl.add(new ColumnDescription("Time Stamp", ValueType.TEXT, "Time Stamp"));
cl.add(new ColumnDescription("", ValueType.TEXT, ""));
cl.add(new ColumnDescription("FTE Id", ValueType.TEXT, "FTE Id"));
cl.add(new ColumnDescription("FTE IP", ValueType.TEXT, "FTE IP"));
cl.add(new ColumnDescription("hide_type", ValueType.TEXT, "hide_type"));
cl.add(new ColumnDescription("hide_buildno", ValueType.TEXT,"hide_buildno"
));
cl.add(new ColumnDescription("hide_env", ValueType.TEXT, "hide_env"));
data.addColumns(cl);
Transactions.exec(new Procedure() {
@SuppressWarnings("deprecation")
@Override
public void execute() throws Throwable {
List<TestResult> rs = new ArrayList<TestResult>();
rs = Transactions.getSession().createCriteria(TestResult.class)
.addOrder(Order.desc("timestamp"))
.setMaxResults(resultCount).list();
String testType = "";
String dataRows = "";
String fteid = "";
String fteIpLink = "";
String Env = "";
String baseUrl = "";
String ftePath = "";
String fteFullPath = "";
String baseUrlFte = "";
String subFteId = "";
String replaceBaseUrlFte = "";
String ftelink = "";
String timeStamp = "";
String dateTime = "";
String summary = "";
TableRow t = new TableRow();
if (rs.size() > 0) {
for (TestResult tr : rs) {
// Filter FteID Variables
baseUrl = tr.getBaseUrl();
ftePath = "reports/?fteid=";
fteFullPath = baseUrl + ftePath;
baseUrlFte = tr.getBaseUrl();
subFteId = "";
replaceBaseUrlFte = baseUrlFte.replaceAll(
"[http:// /]", " ");
if (tr.getTestType().toString().trim()
.equals("BENCHMARK")) {
testType = "<a style=\"color:#58ACFA;text-decoration: none \"
href=\"benchmark.jsp?uid="
+ tr.getResultid()
+ "\" target=\"_blank\">"
+ tr.getTestType() + "</a>";
}
else {
testType = tr.getTestType().toString().trim();
}
// Check FTEId is null
if (tr.getFteid() == null) {
fteid = "";
fteFullPath = "";
replaceBaseUrlFte = "";
}
if (!(tr.getFteid() == null)) {
fteid = tr.getFteid();
if (fteid.length() >= 8) {
subFteId = fteid.substring(0, 8) + "...";
} else {
subFteId = fteid;
}
}
// Check Env is FTE or another
if (tr.getEnvironment().equalsIgnoreCase("FTE")) {
fteIpLink = "<a style=\"color:#58ACFA;text-decoration: none
\"href=https://launch.com/ftes/ftes#/fte/"
+ fteid
+ "/details"
+ " title=\"FTE ID : "
+ fteid
+ " "
+ " "
+ "FTE IP : "
+ baseUrlFte
+ " \">"
+ "</br>"
+ subFteId
+ " </a>";
Env = tr.getEnvironment() + fteIpLink;
}
if (!tr.getEnvironment().equalsIgnoreCase("FTE")) {
Env = tr.getEnvironment();
}
ftelink = "<a style=\"color:#000000;text-decoration: none
\"href=fte.jsp?fteid="
+ fteid
+ "&uid="
+ tr.getResultid()
+ " target=\"_blank\" >" + fteid + "</a>";
timeStamp = tr.getTimestamp().toString().trim();
dateTime = timeStamp.substring(0,
timeStamp.indexOf(".")).replaceAll("-", "/");
summary = "<a style=\"color:#58ACFA;text-decoration: none;\"
href=\"tc.jsp?uid="
+ tr.getResultid()
+ "\" target=\"_blank\">"
+ "<div id=\"summary\" height=\"32\" width=\"32\" >Summary</div>"
+ "</a>";
try {
data.addRowFromValues(tr.getTestExecutionPlan(), tr
.getTestscript().toString(), tr
.getTestStatus().toString(), testType, Env,
tr.getBuildNo().toString(),
"Date(2015,02,07)", summary.toString(),
ftelink.toString(), replaceBaseUrlFte
.toString(), tr.getTestType()
.toString(), tr.getBuildNo()
.substring(0, 6).toString(), tr
.getEnvironment().toString());
} catch (TypeMismatchException e) {
e.printStackTrace();
}
}
}
}
});
JsonNode root = null;
String json = JsonRenderer.renderDataTable(data, true, true)
.toString();
try {
JsonParser parser = new JsonFactory().createJsonParser(json)
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
root = new ObjectMapper().readTree(parser);
} catch (Exception e) {
System.out.println(e.toString());
}
return root.toString();
}
I tried with also like below code snippet changing it something like this.
cl.add(new ColumnDescription("Time Stamp", ValueType.DATETIME, "Time Stamp"
));
data.addRowFromValues(tr.getTestExecutionPlan(), tr.getTestscript().toString
(), tr
.getTestStatus().toString(), testType, Env,
tr.getBuildNo().toString(),
tr.getTimestamp(), summary.toString(),
ftelink.toString(), replaceBaseUrlFte
.toString(), tr.getTestType()
.toString(), tr.getBuildNo()
.substring(0, 6).toString(), tr
.getEnvironment().toString());
when i implement like that return json obj with no column rows.
my data base return date time as 12/5/2014 10:48:25 AM (tr.getTimestamp()
it a date obj)
*My sample json obj*
{"cols":[{"id":"Test Plan","label":"Test Plan","type":"string","pattern":""
},{"id":"Test Script","label":"Test Script","type":"string","pattern":""},{
"id":"Status","label":"Status","type":"string","pattern":""},{"id":"Type",
"label":"Type","type":"string","pattern":""},{"id":"ENV","label":"ENV",
"type":"string","pattern":""},{"id":"Build No","label":"Build No","type":
"string","pattern":""},{"id":"Time Stamp","label":"Time Stamp","type":
"string","pattern":""},{"id":"","label":"","type":"string","pattern":""},{
"id":"FTE Id","label":"FTE Id","type":"string","pattern":""},{"id":"FTE IP",
"label":"FTE IP","type":"string","pattern":""},{"id":"hide_type","label":
"hide_type","type":"string","pattern":""},{"id":"hide_buildno","label":
"hide_buildno","type":"string","pattern":""},{"id":"hide_env","label":
"hide_env","type":"string","pattern":""}],"rows":[{"c":[{"v":"Default suite"
},{"v":"DocManagement_Appxpress_provisioning_Org_myTest"},{"v":"FAILED"},{
"v":"REGRESSION"},{"v":"RCTQ"},{"v":
"15.5.0-central/release/15.5.0-15.5.0_build.11568"},{"v":"Date(2015,02,07)"
},{"v":"<a style=\"color:#58ACFA;text-decoration: none;\"
href=\"tc.jsp?uid=efebb235-dd64-48af-98b0-b4990ae1a92c\"
target=\"_blank\"><div id=\"summary\" height=\"32\" width=\"32\"
>Summary</div></a>"},{"v":"<a style=\"color:#000000;text-decoration: none
\"href=fte.jsp?fteid=&uid=efebb235-dd64-48af-98b0-b4990ae1a92c
target=\"_blank\" ></a>"},{"v":""},{"v":"REGRESSION"},{"v":"15.5.0"},{"v":
"RCTQ"}]}]}
*Sample google chart code to fetch data from REST call*
var data = $.ajax({
url:restUrl ,
dataType:"json",
async: false,
converters: {
"text json": function (data) {
return $.parseJSON(data, true);
}
},
success: function (data) {
console.log(data);
}
}).responseText;
*Date range filter code snippet*
var dateSlider = new google.visualization.ControlWrapper({
'controlType': 'DateRangeFilter',
'containerId': 'control_dateSlider',
'options': {
'filterColumnLabel': 'Time Stamp',
'ui': {'labelStacking': 'vertical', 'label': 'Timeline :'}
}
});
Please i would like to know that how can i pass date object as a google
support format in json with data table and also is there any bug on data
table
addRowFromValues()
with date time type.I have tired possible ways and gone through every
internet articles but can not find any answer.Please if anyone knows that
let me know how to overcome this issue.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-chart-api.
For more options, visit https://groups.google.com/d/optout.