Highcharts get additional info in tool tip form JSON object - json

In Angularjs framework I am using Highcharts to populate bubble chart with JSON object. In tool tip I need to add additional data from JSON object.
I have tried with the formatter function but unable to add additional data from JSON Object.
following is a Plunker link for my issue.
Plunker Example
In the example there is a categories called Cables,
Wallplates & Boxes,
Media Distribution when you click on these category the chart will appear.

The problem is that you return string and use json.parse, which doesn't allow to use functions inside JSON. But you can use workaround. In returned json, reference any string in formatter, but in app.js define formatter function and reference this function after json.parse. It will be clear if you take look at the updated example:
http://plnkr.co/edit/LfGd4N6sC0Q2tHwpPxEx?p=preview

Related

How to deserialize JSON to object in Swift WITHOUT mapping

Is there a way to deserialize a JSON response to a custom object in Swift WITHOUT having to individually map each element.
Currently I am doing it manually with SwiftyJSON but it still requires me to map every field redundantly:
var myproperty1 = json["myproperty1"].stringValue
However coming from a C# background it is as simple as one line of code:
JsonConvert.DeserializeObject<CustomObject>(jsonString); //No mapping needed.
Source - http://www.newtonsoft.com/json/help/html/DeserializeObject.htm
Since I am writing many API endpoints I would like to avoid all the boilerplate mapping code that can be prone to errors. Keep in mind that my JSON responses will be multiple levels deep with arrays of arrays. So any function would need to be recursive.
Similiar question : Automatic JSON serialization and deserialization of objects in Swift
You could use EVReflection for that. You can use code like:
var user:User = User(json:jsonString)
or
var jsonString:String = user.toJsonString()
See the GitHub page for more detailed sample code
You should be able to use key value coding for this. You'd have to make your object a subclass of NSObject for KVC to work, and then you could loop through the elements of the JSON data and use setValue:forKey to assign a value for each key in the dictionary.
Note that this would be dangerous: If the target object did not contain a value for a specific key then your code would crash, so your program would crash on JSON data that contained invalid keys. Not a good thing.

Angular and JSON, having trouble parsing for ng-repeat

I'm horribly sorry if there is a post for this, I tried to search but didn't find a answer.
Problem:
I'm calling a web service and receiving not so well formed JSON data from a Dynamics Nav service:
JSON:
"[{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"},{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"}]"
I then take this JSON and use angular.fromJson(json) to get it properly.
It doesn't seem to change into an array of javascript objects, but just plain text.
However if I take the same JSON and just put it manually in like this:
var json = angular.fromJson(stringfromserver);
It turns into a proper javascript object and ng-repeat throws no error.
I found an answer on Quora:
--- Le Batoure,
Angular from json is now strict so assuming that this string is from a trusted source you would have to use "eval()" plus surround the call in parenthesis for it to work
var hatsData = angular.fromJson(eval("(" + hats + ")"))
If you bring your JSON from http request for example you don't need to use the fromJson method.
The JSON is automatically parsed by Angular and you can use it directly.

Fusion Charts for representing data in graphical form

I am trying to render my data in a graph using fusion charts. I have a web service that returns the data in JSON format. I want to render chart for that data. can I directly give the URL of my web service so that I cannot set key value pairs. Is it possible to do so/ Can any one please tell me how to do this.
It can use a JSON URL/feed, a JSON Object (in JavaScript) or JSON String. This functionality is provided by FusionCharts class method setJSONUrl(). Example
myChart.setJSONUrl("Data.json");
See http://docs.fusioncharts.com/charts/contents/FirstChart/JSONData.html
FusionCharts Suite has a specific JSON structure for each category of charts. While passing the data to render method, data is expected in the pre defined format. Please refer to: http://docs.fusioncharts.com/charts/contents/DataFormats/JSON/Overview.html

Pass Json Object from Play! framework to HighCharts JS

http://www.playframework.com/documentation/2.1.x/JavaTodoList
Using the above tutorial as a reference, I have created an application which sends data from the model to view via the Application controller.
I have managed to display the model(Tasks) as a high chart. The code is here.
public static Result format(){
return ok(views.html.frmt.render("Visualize it",Task.all()));
}
This goes to this view page.
http://ideone.com/ycz9ko
Currently, I use scala templating inside the javascript code itself. Refer to lines 9-14 and lines 20-24.This unelegant style of doing things is not really optimal.
I want to be able to accomplish the above using Json instead.
public static Result jsonIt(){
List<Task> tasks = Task.all();
return ok(Json.toJson(tasks));
}
My Qns are how to send the JSON objects to a view template.
And how to parse it into a Highcharts format. Is there some standard procedure to do this ? Or else I have to write my own method to do this ?
It'll great if someone can show me a code snippet. Also I would prefer a post not using Ajax. I would just want to know how to do this first.
I also found this stackoverflow post useful.how to parse json into highcharts. However, it didnt answer the part about converting from Play format to Highcharts format.
Thanks in advance
You don't need to pass a json object to your template, instead you might do an ajax call from your client side javascript (your template) and get json response that you could use futher in javascript code to build a chart. For example :
You have some path that is bind to your controller jsonIt() like so /chartsdata/json
then using jquery shorthand for ajax request:
var chart_data = $.get('/chartsdata/json', function(data) {
return data;
});
now you can use a chart_data that is an array of objects where each object represents a Task, in your further javascript code to build a chart.

Setting a JSON Object from an input field

I basically have the following flow:
XML -> JSON -> Spring MVC -> jsp page, which is displayed as a table with editable fields.
How do make is so that when i edit a field value it correct updates the Json Object?
I have used some nasty hacking at the moment, as i know (testing) the values/object I am going to get, so im just parsing the JSON string in javascript and sending that back.
So i can then just convert the json object (with new values) and post it back.
Cheers.
You could use the serialize method from prototypejs.
http://www.prototypejs.org/api/form/serialize
just by calling .serialize() you'll be able to get the updated object.