how to use json array in FusionCharts? - java

I am using fusion chart in my application.I am taking json array from servlet to javascript.
Code :
var customerCountList=response.sharecountlist;
FusionCharts.ready(function(){
var revenueChart = new FusionCharts({
type: "column3d",
renderAt: "spraybookerCount-bar",
width: "500",
height: "300",
dataFormat: "json",
dataSource: {
"chart": {
"caption": "Revenue for last year",
"palettecolors": "e44a00",
"subCaption": "Harry's SuperMart",
"xAxisName": "refvalue",
"yAxisName": "['viewcount']",
"theme": "carbon"
},
"data"://here i want to use response.sharecountlist
}
});
revenueChart.render("spraybookerCount-bar");
});
here sharecountlist is sharecountlist==[{"viewcount":99,"refvalue":"Guest"},{"viewcount":4,"refvalue":"facebook"},{"viewcount":2,"refvalue":"friend"}].
sharecountlist is dynamic ,so how can I use this sharecountlist in place of data in above code. Please help me.
Thanks.

Related

Save JSON request as Item in dynamoDb

I have a request of the following JSON format:
{
"profile": {
"created": 1505202655,
"createdBy": "abc",
"updated": 1505202655,
"updatedBy": "xyz"
},
"likesId": [
"0010127916"
],
"icon": null,
"Attributes": {
"backgroundColor": "#FFFFFF",
"logo": "images/Logos/P0010127916.jpg",
"textColor": "#000000"
},
"profileId": "PACYG0010916",
"restrictions": {
"clients": [
"Android",
"SmartTv"
],
"UserTypes": [
"user1",
"user2"
],
"periodEnd": 1512978849,
"periodStart": 1505202849
},
}
I am trying to save the above JSON request Object in the dynamoDb table using putItem. However I am stuck in some issues which are as follows:
Can I store this whole JSON request as-is(without escaping double quotes) in the form of item in dynamodb table?
In case of likesId and Attributes I am storing them as a List and Map with the help of .withList and .withMap methods respectively, but in case of profile I have taken it as a POJO which has 4 states, how can I save this object with the putItem as I did not find any method for saving objects like this, as we have methods for string, numbers and other datatypes, how can I save my own object?
Any kind of guidance will be highly appreciated as I am new to dynamoDb and learning it by doing POC.
You should be able to save it quite easily with the DocumentClient class:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property
var params = {
TableName : 'Table',
Item: item
};
var documentClient = new AWS.DynamoDB.DocumentClient();
documentClient.put(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
Where item is the object from your original question

how to iterate json on servlet

i have json like
{
"condition": "AND",
"rules": [{
"id": "BirthDate",
"field": "BirthDate",
"type": "date",
"input": "text",
"operator": "equal",
"value": "2016/04/13"
}]}
i just want to iterate it on servlet for that i create
public String getRuleList(){
String ruleList=this.get("rules");
return ruleList;
}
public String getcondition(){
return this.get("condition");
}
as getter setter when i send this json without using JSON.stringify i got the value of condition but unable to fetch rules.By using JSON.stringify i unable to fetch anything. please help..
rules is JSONArray and simple get returns an object. Try to get it with the json libraries custom method.
If you are using org.json try this
this.getJSONArray('rules')
Try to provide some more information such as the json library you are using, the output you got for this.get('rules') and how is this initialized for a much better answer
To solve above problem i do
result =JSON.stringify(result);
var json = JSON.parse(result);
var queryData={
rules:JSON.stringify(json.rules),
condition:JSON.stringify(json.condition)
};
console.log("result"+JSON.stringify(result));
if (!$.isEmptyObject(result)) {
var url = location.protocol + "//" + location.host +appContext+"?command=QueryBuilderServlet&action=getQueryJson";
$.ajax({
url:url,
type: "POST",
data:queryData,
dataType:'json',
});
thanks a lot for your help

Passing form Data to servlet using Extjs

i'm new in ExtJS and Servlet.
I created a form with 2 fields usinf ExtJS :
var panel = Ext.create('Ext.form.Panel',
{
title: 'Personnal Data',
bodyPainting: 5,
width: 350,
region:'center',
url: 'save_form.php',
items:
[{
xtype: 'textfield',
fieldLabel: 'First Name ',
name: 'firstName'
},
{
xtype: 'textfield',
fieldLabel: 'Last Name ',
name: 'lastName'
}],
buttons:
[{
text: 'Submit',
handler: function()
{
var formData = this.up('form').getForm();
}
}]
});
But i don't know how to pass the value of the two fields to a servlet, by clicking on the button.
And how can i retrieve the data entered in the form, in the servlet ?
Thank you !
By default ExtJS Forms will send over the values in an "ajax" fashion and I believe it will be a "post". In your servlet (assuming you are posting to a servlet defined in your web.xml file) in your doPost (or doGet) methods, use the "request" variable in the method and do
request.getParameter("firstName")
and
request.getParameter("lastName")
.
Link to HttpServlet Definition (is the same for just about every java container).
Edit:
In your handler you need to add:
formData.submit();

Iterating Json Object in Jquery?

I want to know how to iterate a JSON object using jQuery. My requirement is I am getting a list from a Java Servlet to the UI and I have to populate a combo box with the AJAX response.
The above tack I already did it using struts2 and jQuery. Now I am in the middle of nowhere, how to iterate the Java List back in JSP:
$("#XXX option").remove();
$.each(data.YYYList, function(index, item) {
$("#XXX").append($("<option></option>").text(item).val(item));
});
I have set the MIME type as response.setContentType("application/json");
Can any one please guide me how to achieve this. Please let me know if any other information is needed from me.
Based on the small amount of information given by Esh, here is an example that I created for the very function you listed. I have a JSON that I want to be used in multiple select boxes.
Fiddle
Example Json:
"yyyList": [
{
"Id": "1",
"Name": "aaaa "
}, {
"Id": "2",
"Name": "bbb "
}, {
"Id": "6",
"Name": "ccc "
}, {
"Id": "7",
"Name": "ddd "
} ]
$.ajax({
url: "URL",
//data: "",
type: "GET",
dataType: 'json',
success: function (data) {
$.each(data.YYYList, function () {
$('#state').append('<'option value='+this.Id+'>'+this.Name+'<'option>');
});
}
})
$('#state') ---> gives the same id for select tag in HTML
Please make correct it option syntax
Hope this helps.

jQuery access java Map of string object where the object is a map of strings

I am trying to return two json sets from java which each contain key/value pairs. I can get the data to return as expected but once I have the data I can not access it properly. Here is what my data coming from the java looks like
{"RESULTS":
{"MAP_1":
[
{"value":"1","display":"output text","type":"type a"},
{"value":"2","display":"more output text","type":"type a"}
],
"MAP_2":
[
{"value":"1","display":"output text","type":"type b"},
{"value":"2","display":"more output text","type":"type b"}
]
}
}
I have tried using $.map and $.each but I can not seem to drill into the data any help would be greatly appeciated.
Here is my latest attempt:
$.ajax({
url: url,
dataType: "text",
data: {
searchString: request.term
},
success: function( data ) {
response( $.map( data.MAP_1, function( item ) {
label: item.value + ", " + item.type
value: item.display
}));
}
});
Thanks in advance!
The format of the data returned by java is text, not json. So you should specify the dataType as json. In addition the following code are not right, I think.
data.MAP_1
should be
data.RESULTS.MAP_1

Categories