I am trying to use the JQCloud jquery plugin to generate a tag cloud from some Elasticsearch data. The main issue I am facing is that the data I get back is formated using the terms 'key' for tag and 'doc_count' for the number of times the tag shows up in the data. I've tried a few different ways of getting the data to parse correctly but the tag cloud never shows up on the page, nor am I getting any great information from the Chrome Dev tools console.
First call
$(document).ready(function(){
$.ajax({
url: "/tags",
type: "get",
async: false,
success: function(data){
$("#wordCloud").jQCloud([{text: data[0].key, weight: data[0].doc_count}, {text: data[1].key, weight: data[1].doc_count}]);
}
});
});
Second call
$(document).ready(function(){
$.ajax({
url: "/tags",
type: "get",
async: false,
success: function(data) {
var json = JSON.parse(data);
$("#tagcloud").jQCloud([json]);
}
});
});
Both of these suggestions were taken from Import a JS array using ajax to pass though to a function/plugin in JQuery.
[{"key": "ibm_created", "doc_count": 85}, {"key": "ibm_dedicated_public", "doc_count": 74}, {"key": "ibm_third_party", "doc_count": 40}, {"key": "p", "doc_count": 31}, {"key": "service", "doc_count": 30}, {"key": "bluemix", "doc_count": 29}, {"key": "development", "doc_count": 29}, {"key": "cloud", "doc_count": 28}]