Hi working in Jolt transformation tool and getting know some in-depth details
Input
{
"characteristic": [
{
"name": "usageCharacteristicName",
"value": "availableBalance",
"#type": "usageCharacteristic",
"arrayIndex": "2"
},
{
"name": "usageCharacteristicValue",
"value": "2999.25",
"#type": "usageCharacteristic",
"arrayIndex": "2"
},
{
"name": "usageCharacteristicName",
"value": "Name",
"#type": "usageCharacteristic",
"arrayIndex": "0"
},
{
"name": "usageCharacteristicValue",
"value": "Jack",
"#type": "usageCharacteristic",
"arrayIndex": "0"
},
{
"name": "usageCharacteristicName",
"value": "Likes",
"#type": "usageCharacteristic",
"arrayIndex": "1"
},
{
"name": "usageCharacteristicValue",
"value": "Code",
"#type": "usageCharacteristic",
"arrayIndex": "1"
}
]
}
Jolt Spec :
[
{
"operation": "shift",
"spec": {
"characteristic": {
"*": {
"arrayIndex": {
"2": {
"#(2,value)": "data.queryBalance.accountBalance"
},
"0": {
"#(2,value)": "data.queryBalance.Name"
},
"1": {
"#(2,value)": "data.queryBalance.Likes"
},
}
}
}
}
}
]
Output :
{
"data" : {
"queryBalance" : {
"accountBalance" : [ "availableBalance", "2999.25" ],
"Name" : [ "Name", "Jack" ],
"Likes" : [ "Likes", "Code" ]
}
}
}
the Output i was getting is not good enough for me, want to do like String like bellow Expected.
Expected Output :
"availableBalance" : "2999.25",
"Name" : "Jack",
"Likes" : "Code"
how do i get like a String ?
I think this solve the problem
spec
[
{
//group keys and valeus for arrayIndex
"operation": "shift",
"spec": {
"characteristic": {
"*": {
"value": "newArray[#(1,arrayIndex)].#(1,name)"
}
}
}
},
{
//create a new object use a key and valeus matchs previous
"operation": "shift",
"spec": {
"newArray": {
"*": {
"usageCharacteristicValue": "#(1,usageCharacteristicName)"
}
}
}
}
]
output
{
"Name" : "Jack",
"Likes" : "Code",
"availableBalance" : "2999.25"
}
You need a modify transformation spec as well such as
[
{
// reduce to simple array "value" : [ "availableBalance", "2999.25" ] nested within an object
"operation": "shift",
"spec": {
"*": {
"*": {
"value": "&"
}
}
}
},
{
// combine components of the array so as to reform as a string
"operation": "modify-overwrite-beta",
"spec": {
"*": "=join(' : ',#(1,&))"
}
}
]
Edit: You can alternatively try the following for the new case :
[
{
// dissipate each array into different object with respect to arrayIndex values
"operation": "shift",
"spec": {
"*": {
"*": {
"value": "#(1,arrayIndex).&"
}
}
}
},
{
// combine components of each array colon-separatedly
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=join(' : ',#(1,&))"
}
}
},
{
// convert to a unique array
"operation": "shift",
"spec": {
"*": {
"*": "&"
}
}
},
{
// combine components of each array comma-separatedly
"operation": "modify-overwrite-beta",
"spec": {
"*": "=join(' , ',#(1,value))"
}
}
]
I know how to do it by another library Josson. You may consider to use it.
https://github.com/octomix/josson
Deserialization
Josson josson = Josson.fromJsonString(inputJSON);
Transform to an array of string
JsonNode node = josson.getNode(
"characteristic" +
".group(arrayIndex)" +
".concat(elements[name='usageCharacteristicName'].value" +
" ,' : '" +
" ,elements[name='usageCharacteristicValue'].value)");
System.out.println(node.toPrettyString());
Output
[ "availableBalance : 2999.25", "Name : Jack", "Likes : Code" ]
Transform to a single string
String str = josson.getString(
"characteristic" +
".group(arrayIndex)" +
".concat(elements[name='usageCharacteristicName'].value" +
" ,' : '" +
" ,elements[name='usageCharacteristicValue'].value)" +
".join(', ')");
System.out.println(str);
Output
availableBalance : 2999.25, Name : Jack, Likes : Code
Transform to a map
JsonNode node = josson.getNode(
"characteristic" +
".group(arrayIndex)" +
".map(elements[name='usageCharacteristicName'].value::elements[name='usageCharacteristicValue'].value)" +
".mergeObjects()");
System.out.println(node.toPrettyString());
Output
{
"availableBalance" : "2999.25",
"Name" : "Jack",
"Likes" : "Code"
}
Transform to a map with sorted "arrayIndex" as key
JsonNode node = josson.getNode(
"characteristic" +
".group(arrayIndex)" +
".sort(arrayIndex)" +
".map(arrayIndex.prepend('arrayIndex')::" +
" concat(elements[name='usageCharacteristicName'].value" +
" ,' : '" +
" ,elements[name='usageCharacteristicValue'].value))" +
".mergeObjects()");
System.out.println(node.toPrettyString());
Output
{
"arrayIndex0" : "Name : Jack",
"arrayIndex1" : "Likes : Code",
"arrayIndex2" : "availableBalance : 2999.25"
}
Related
I have made a page allowing to see tools arranged in classes and subclasses (3rd floor).
The tools database is on a server, and I receive the data as JSON.
Everything was working fine until I added a number of tools (and therefore classes)
My tools appear several times without reason in classes that are not the right ones.
I checked the JSON, no problem.
Here are screenshots of the problem and the code that allows me to retrieve the data and send it to my adapter.
Thanks for your help.
Random display problem image 1
Random display problem image 2
Random display problem image 3
ArrayList<String> famille1 = new ArrayList<>();
ArrayList<String> typeliste = new ArrayList<>();
HashMap<String, HashMap<String, HashMap<String, ArrayList<MatosItem>>>> ma = new HashMap<>();
ArrayList<String> materiauliste = new ArrayList<>();
HashMap<String, HashMap<String, HashMap<String, ArrayList<MatosItem>>>> materielsItemList = new HashMap<>();
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
#Override
public void run() {
FetchData fetchData = new FetchData("http://" + adresseIp.getAdresseIP() + "/jsonmateriels.php");
if (fetchData.startFetch()) {
if (fetchData.onComplete()) {
String json = fetchData.getResult();
try {
HashMap<String, HashMap<String, ArrayList<MatosItem>>> typeItemList = new HashMap<>();
JSONObject jsonObject = new JSONObject(json);
JSONArray jsonArrayOutils = jsonObject.getJSONArray("Outils");
for (int j = 0; j < jsonArrayOutils.length(); j++) {
HashMap<String, HashMap<String, ArrayList<MatosItem>>> typeItemList1 = new HashMap<>();
JSONObject fam = jsonArrayOutils.getJSONObject(j);
String famille = fam.names().getString(0);//permet d'avoir les choses contenu dans la classe soudeurs
JSONArray jsonArrayFamille = fam.getJSONArray(famille);//permet de récupérer le suivant
famille1.add(famille);
for (int i = 0; i < jsonArrayFamille.length(); i++) {
HashMap<String, ArrayList<MatosItem>> matItemList = new HashMap<>();
JSONObject typ = jsonArrayFamille.getJSONObject(i);
String type = typ.names().getString(0);
JSONArray jsonArrayType = typ.getJSONArray(type);
typeliste.add(type);
for (int k = 0; k < jsonArrayType.length(); k++) {
JSONObject mat = jsonArrayType.getJSONObject(k);
ArrayList<MatosItem> outils = new ArrayList<>();
String materiau = mat.names().getString(0);
JSONArray jsonArraylistout = mat.getJSONArray(materiau);
materiauliste.add(materiau);
for (int l = 0; l < jsonArraylistout.length(); l++) {
JSONObject out = jsonArraylistout.getJSONObject(l);
String description = out.getString("description");
String id = out.getString("id");
String ref = out.getString("ref");
String code_fourn = out.getString("code_fourn");
Log.e("boucle",description+id);
outils.add(new MatosItem(description, id, false, ref, code_fourn));
}
matItemList.put(materiau, outils);
}
typeItemList1.put(type, matItemList);
}
materielsItemList.put(famille, typeItemList1);
tabLayout.addTab(tabLayout.newTab().setText(famille));
}
ArrayList<String> list = new ArrayList<>();
for (String i : Objects.requireNonNull(materielsItemList.get(famille1.get(0))).keySet()) {
list.add(i);
Log.e(TAG, "run: "+i );
}
typeItemList = materielsItemList.get(famille1.get(0));
Log.e(TAG, "run: "+typeItemList );
matosListView.setAdapter(new MatosItemAdapter(context, typeItemList,list ));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
// get the current selected tab's position and replace the fragment accordingly
Fragment fragment = null;
if (tab.isSelected()) {
ArrayList<String> list = new ArrayList<>();
for (String i : Objects.requireNonNull(materielsItemList.get(famille1.get(tab.getPosition()))).keySet()) {
list.add(i);
}
HashMap<String, HashMap<String, ArrayList<MatosItem>>> typeItemList1 = new HashMap<>();
typeItemList1 = materielsItemList.get(famille1.get(tab.getPosition()));
matosListView.setAdapter(new MatosItemAdapter(context, typeItemList1, list));
}
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
progressBar.setVisibility(GONE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
});
I checked the JSON
I tried to use a thread
{
"Outils" : [{
"Soudeurs" : [
{
"Fils" : [
{
"Fil" : [
{
"description" : "Fil MIG G3SI1 diam 1.2",
"id" : "26",
"ref" : "bobine de 15 kg",
"code_fourn" : "x"
},
{
"description" : "Fourre OK1413 diam 1.2",
"id" : "45",
"ref" : "bobine 16 kg avec gaz",
"code_fourn" : "x"
},
{
"description" : "MIG inox 316L SI diam 1.2",
"id" : "46",
"ref" : "bobine 15 kg",
"code_fourn" : "x"
}]
}]
},
{
"Materiel de soudure" : [
{
"Gaine guide" : [
{
"description" : "fil 25 x 45 4M diam 1.2",
"id" : "27",
"ref" : "x",
"code_fourn" : "x"
}
]},
{
"Batterie" : [
{
"description" : "Warrior AIR ESAB",
"id" : "47",
"ref" : "x",
"code_fourn" : "x"
}
]},
{
"Cagoule" : [
{
"description" : "Couvre nuque noire ESAB",
"id" : "48",
"ref" : "x",
"code_fourn" : "x"
}
]},
{
"Protection" : [
{
"description" : "Ecran de protection bleu",
"id" : "49",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Visiere transparente pour ecran HG930B",
"id" : "50",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Visiere teinte pour ecran HG930B",
"id" : "51",
"ref" : "x",
"code_fourn" : "x"
}
]},
{
"Pince" : [
{
"description" : "Stubby original 400 A",
"id" : "52",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Masse bronze GCB 450 A",
"id" : "53",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Masse bronze GCB 600 A",
"id" : "54",
"ref" : "x",
"code_fourn" : "x"
}]
}]
},
{
"Electrodes" : [
{
"OK4627" : [
{
"description" : "Diam 2.5 x 350 rutile",
"id" : "25",
"ref" : "x",
"code_fourn" : "x"
}]
},
{
"OK4800" : [
{
"description" : "Diam 2.5 x 350",
"id" : "32",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Diam 3.2 x 350",
"id" : "33",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Diam 4 x 350",
"id" : "34",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Diam 5 x 450",
"id" : "35",
"ref" : "x",
"code_fourn" : "x"
}]
},
{
"Inox 316 L 17" : [
{
"description" : "Diam 2.5 x 300",
"id" : "36",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Diam 3.2 x 350",
"id" : "37",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "Diam 4 x 350",
"id" : "38",
"ref" : "x",
"code_fourn" : "x"
}]
},
{
"Gougeage" : [
{
"description" : "6 x 305",
"id" : "39",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "8 x 305",
"id" : "40",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "10 x 305",
"id" : "41",
"ref" : "x",
"code_fourn" : "x"
}]
},
{
"Nue" : [
{
"description" : "9.5 x 914 slice",
"id" : "42",
"ref" : "x",
"code_fourn" : "x"
}]
}]
}]},
{
"Ajusteurs" : [
{
"Accessoires" : [
{
"Nettoyant" : [
{
"description" : "26.5 kg alfa marine",
"id" : "44",
"ref" : "x",
"code_fourn" : "x"
}]
}]
},
{
"Hydraulique" : [
{
"Huile" : [
{
"description" : "Enerpac HF95Y bidon 5L",
"id" : "43",
"ref" : "x",
"code_fourn" : "x"
}]
}]
}]
},
{
"Machinistes" : [
{
"Accessoires" : [
{
"Lame ebavureur" : [
{
"description" : "E100S (longue) boite de 10",
"id" : "30",
"ref" : "x",
"code_fourn" : "x"
},
{
"description" : "B10S (courte) boite de 10",
"id" : "31",
"ref" : "x",
"code_fourn" : "x"
}]
}]
}]
}]
}
I would like to have a correct display of the tools and their class. I don't have to have expandables list
I am trying to transform a JSON using Jolt transformation looking for some input here.
I am trying to get all the items from all the levels into an array.
My goal is to get an array that contains all the items without knowing how many levels I have in the json.
Here is my input and expected output:
if I've 3 levels:
Input:
{
"id": 11,
"item": [
{
"id": "11_1",
"item": [
{
"id": "11_1_1",
"item": [
{
"id": "11_1_1_1"
}
]
},
{
"id": "11_1_2",
"item": [
{
"id": "11_1_2_1"
}
]
}
]
}
]
}
Expected output:
[
{
"id": "11_1"
},
{
"id": "11_1_1"
},
{
"id": "11_1_1_1"
},
{
"id": "11_1_2"
},
{
"id": "11_1_2_1"
}
]
if I've 2 levels:
Input:
{
"id": 11,
"item": [
{
"id": "11_1",
"item": [
{
"id": "11_1_1"
},
{
"id": "11_1_2"
}
]
}
]
}
Expected output:
[
{
"id": "11_1"
},
{
"id": "11_1_1"
},
{
"id": "11_1_2"
}
]
I tried to write something like:
[
{
"operation": "shift",
"spec": {
"item": { //to cover the second level
"*": "item"
}
}
},
{
"operation": "shift",
"spec": {
"item": {
"*": { //to cover the 3td level
"item": {
"*": "item"
}
}
}
}
}
]
The result was null, if I run each transformation separately, I get results when applicable
Can you please help me to write a simple spec that will do this?
If the inputs have at most 3 levels as in your case, then use this spec
[
{
"operation": "shift",
"spec": {
"item": {
"*": {
"id": "&",
"item": {
"*": {
"id": "&",
"item": {
"*": {
"id": "&"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"id": {
"*": "[#1].&1"
}
}
}
]
in order to handle the both cases using only this one. If one more level is needed as well, then add
,
"item": {
"*": {
"id": "&"
}
}
just after the inner most
"id": "&"
Edit : If you have some other attributes than id as lately commented like in the below input sample
{
"id": 11,
"item": [
{
"id": "11_1",
"quantity": 1,
"action": "add",
"state": "x",
"item": [
{
"id": "11_1_1",
"quantity": 2,
"action": "drop",
"state": "y"
},
{
"id": "11_1_2",
"quantity": 3,
"action": "modify",
"state": "z"
}
]
}
]
}
than just a little modification would handle your new case :
[
{
"operation": "shift",
"spec": {
"item": {
"*": {
"*": "&",
"item": {
"*": {
"*": "&",
"item": {
"*": {
"*": "&"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[#1].&1"
}
}
}
]
which would generate :
[
{
"id": "11_1",
"quantity": 1,
"action": "add",
"state": "x"
},
{
"id": "11_1_1",
"quantity": 2,
"action": "drop",
"state": "y"
},
{
"id": "11_1_2",
"quantity": 3,
"action": "modify",
"state": "z"
}
]
Solution for unlimited levels using library Josson.
https://github.com/octomix/josson
Deserialization
Josson josson = Josson.fromJsonString(
"{" +
" \"id\": 11," +
" \"item\": [" +
" {" +
" \"id\": \"11_1\"," +
" \"quantity\": 1," +
" \"action\": \"add\"," +
" \"state\": \"x\"," +
" \"item\": [" +
" {" +
" \"id\": \"11_1_1\"," +
" \"quantity\": 2," +
" \"action\": \"drop\"," +
" \"state\": \"y\"" +
" }," +
" {" +
" \"id\": \"11_1_2\"," +
" \"quantity\": 3," +
" \"action\": \"modify\"," +
" \"state\": \"z\"" +
" }" +
" ]" +
" }" +
" ]" +
"}");
Transformation
JsonNode node = josson.getNode("item.cumulateCollect(field(item:), item)");
System.out.println(node.toPrettyString());
Statement field(item:) removes field item from the current object.
The 2nd argument of cumulateCollect() means the next level. In this case is item.
Output
[ {
"id" : "11_1",
"quantity" : 1,
"action" : "add",
"state" : "x"
}, {
"id" : "11_1_1",
"quantity" : 2,
"action" : "drop",
"state" : "y"
}, {
"id" : "11_1_2",
"quantity" : 3,
"action" : "modify",
"state" : "z"
} ]
How to keep other fields in the Jolt transform JSON array, I am trying to use wildcard but fields are not added in the final output?
Here is the example input I am using
[
{
"foundduring": "D-DC",
"user_type": "type1",
"location": "location1"
},
{
"foundduring": "D-DG",
"user_type": "type2",
"location": "location2"
},
{
"foundduring": "D-DI",
"user_type": "type3",
"location": "location3"
}
]
I am using the following Jolt transformation and also trying wildcard:
[
{
"operation": "shift",
"spec": {
"*": {
"foundduring": {
"D-DC": {
"#CycleCount": "[&3].foundduring"
},
"D-DG": {
"#Pick": "[&3].foundduring"
},
"D-DI": {
"#Issue": "[&3].foundduring"
}
},
"#": "&"
}
}
}
]
Following is my expected output where shift operation happened and then need to keep all other fields as it it
[
{
"foundduring" : "CycleCount",
"user_type" : "type1",
"location" : "location1"
},
{
"foundduring" : "Pick",
"user_type" : "type2",
"location" : "location2"
},
{
"foundduring" : "Issue",
"user_type" : "type3",
"location" : "location3"
}
]
Actual Output coming:
[
{
"foundduring": "CycleCount"
},
{
"foundduring": "Pick"
},
{
"foundduring": "Issue"
}
]
Consider using "*" wildcard as else case instead of "#" such as
[
{
"operation": "shift",
"spec": {
"*": {
"foundduring": {
"D-DC": {
"#CycleCount": "[&3].&2"
},
"D-DG": {
"#Pick": "[&3].&2"
},
"D-DI": {
"#Issue": "[&3].&2"
}
},
"*": "[&1].&"
}
}
}
]
Btw, no need to get the key name "foundduring", just use &2 substitution to go 2 level up from the current branch and grab that value.
The demo on the site http://jolt-demo.appspot.com/ is
You may consider another library Josson.
https://github.com/octomix/josson
Deserialization
Josson josson = Josson.fromJsonString(
"[" +
" {" +
" \"foundduring\": \"D-DC\"," +
" \"user_type\": \"type1\"," +
" \"location\": \"location1\"" +
" }," +
" {" +
" \"foundduring\": \"D-DG\"," +
" \"user_type\": \"type2\"," +
" \"location\": \"location2\"" +
" }," +
" {" +
" \"foundduring\": \"D-DI\"," +
" \"user_type\": \"type3\"," +
" \"location\": \"location3\"" +
" }" +
"]");
Transformation
JsonNode node = josson.getNode(
"field(foundduring.caseValue('D-DC','CycleCount','D-DG','Pick','D-DI','Issue'))");
System.out.println(node.toPrettyString());
Output
[ {
"foundduring" : "CycleCount",
"user_type" : "type1",
"location" : "location1"
}, {
"foundduring" : "Pick",
"user_type" : "type2",
"location" : "location2"
}, {
"foundduring" : "Issue",
"user_type" : "type3",
"location" : "location3"
} ]
I have a JSON response that looks like the following:
[
{
"id": 5,
"user_id": 1,
"message": "Hello",
"children": [
{
"id": 7,
"user_id": 2,
"message": "Hi",
"children": [
{
"id": 8,
"user_id": 3,
"message": "Hey",
"children": [
]
}
]
}
]
},
{
"id": 6,
"user_id": 4,
"message": "Ahoy",
"children": [
]
}
]
I already have the model created (Message.java). The children can be retrieved by calling getChildren(). The response is saved in a list List<Message> messages.
How can I loop through this JSON array to get the contents of each child until there is no child left? Is this possible without a recursive function?
I Assume you have List messages :
Here is how you can browse through all children with both recursion and iterative way :
List<Message> messages = //you already have that
System.out.println("Using Recusion : ");
for (Message message : messages) {
printMessage(message);
}
System.out.println("Using Iterative : ");
Stack<Message> stack = new Stack<>();
stack.addAll(messages);
while (!stack.empty()) {
Message item = stack.pop();
System.out.println(item.getId() + ":" + item.getUser_id() + ":" + item.getMessage());
for (Message chidren : item.getChildren()) {
stack.push(chidren);
}
}
and here is the printMessage method :
public static void printMessage(Message pmessage) {
System.out.println(pmessage.getId() + ":" + pmessage.getUser_id() + ":" + pmessage.getMessage());
for (Message message : pmessage.getChildren()) {
printMessage(message);
}
}
public void printJsonObject(JSONObject jsonObj) {
for (String keyStr : jsonObj.keySet()) {
Object keyvalue = jsonObj.get(keyStr);
//Print key and value
System.out.println("key: "+ keyStr + " value: " + keyvalue);
//for nested objects iteration if required
if (keyvalue instanceof JSONObject)
printJsonObject((JSONObject)keyvalue);
}
}
I m using highcharts.js for my project What I'm trying to do is format my tool tip. I have written a java method which is returning me the output in the json format as
syList:
[{
"value1": "Some Area",
"value2": "1",
"agrAcronym": "AB"
}, {
"value1": "Some AREA",
"value2": "2",
"agrAcronym": "BA"
}, {
"value1": "Some Area",
"value2": "3",
"agrAcronym": "NA"
}, {
"value1": "Some Area",
"value2": "4",
"agrAcronym": "MW"
}, {
"value1": "Some Area",
"value2": "5",
"agrAcronym": "PW"
}, {
"value1": "Some Area",
"value2": "6",
"agrAcronym": "NP"
}, {
"value1": "Some Area",
"value2": "7",
"agrAcronym": "SP"
}, {
"value1": "Some Area",
"value2": "8",
"agrAcronym": "MS"
}, {
"value1": "Some Area",
"value2": "9",
"agrAcronym": "SA"
}],
my chart script is
var options2 = {
chart : {
renderTo : 'outgoingContainer',
type : 'column',
marginTop: 50,
},
title : {
text : 'Something Area',
style: {
color : '#2B1B17',
fontWeight: 'bold'
}
},
xAxis : {
title : {
text : null
},
labels: {
y: 30,
}
},
yAxis : {
title : {
text : 'something',
align : 'middle'
},
stackLabels : {
enabled : true,
style : {
fontWeight : 'bold',
color : (Highcharts.theme && Highcharts.theme.textColor)
|| 'charcoal'
},
formatter : function() {
return getCurrencyFormat(parseInt(this.total));
}
}
},
tooltip : {
formatter : function() {
return '' + this.x + ': ' + getCurrencyFormat(parseInt(this.y));
}
},
plotOptions : {
series: {
borderWidth: 1,
borderColor: 'black'
},
column : {
stacking : 'normal',
dataLabels : {
enabled : false,
color : (Highcharts.theme && Highcharts.theme.dataLabelsColor)
|| 'black',
style : {
fontWeight : 'bold',
}
}
}
},
legend : {
enabled : false
},
credits : {
enabled : false
},
series : [ {
color : '#00FFFF',
} ]
};
$.getJSON(
function(data) {
options2.xAxis.categories = [];
options2.series[0].data = [];
if (data["syList"] != null)
{
$.each(data["syList"], function( index, value ) {
options2.xAxis.categories[index] = data["syList"][index] ["value1"];
options2.series[0].data[index] = parseFloat(data["syList"][index]["value2"]);
});
$("#outgoingContainer").show();
} else {
options2.yAxis.title.text = "";
$("#outgoingContainer").hide();
}
new Highcharts.Chart(options2);
});
You need to set useHtml = true on your tooltip and this will allow you to format your tooltip any way that you want. Make sure that the data for your series is set to syList and set the headerFormat, pointFormat, and footerFormat on your tooltip like this. Note the {point.agrAcronym}.
tooltip: {
shared: true,
useHTML: true,
headerFormat: '<table>',
pointFormat: '<tr><td style="color: {series.color};">{series.name}: </td>' +
'<td>{point.agrAcronym}</td></tr>',
footerFormat: '</table>'
},
series: [{
data: syList
}]