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.