Using the Ajax updated Dataset with Cross Filter

I have a really large dataset (about 500,000 records ...) about CO2 emissions in London that I want to display using maps and charts using crossfilter. For performance reasons, I want to make requests in advance in city blocks, so I made an ajax function that does this dynamically when I click on a city (just imagine a map of London with city boundaries where we can click on them). Ajax code works fine:

function load_data(str){ var londonData = null; $.ajax({ url: "php/london-data.php", data: "name='"+str+"'", type: 'get', async: false, success: function(data) { londonData = data; } }); alert(JSON.stringify(londonData)); return londonData;} 

It returns a json file. When I click on a city, the warning function shows me that the data is updated. But to use crossfilter, I wanted to have a global variable that is updated when you click on the area, thanks to the load_data function, but it does not work - the variable retains the same value as during initialization.

I don’t know if I am enough, but do you think there is a solution to update this global variable and, as a result, update the cross-filter data? Sort of:

 layer.on("click", function (e) { londonData = load_data(/*name of the layer clicked on*/) }); dataset = crossfilter(londonData); 

In the end, I would like my charts to be updated when I click on a city, so the 'dataset' variable should change when I click on it. I do not know if this is possible, or if I am completely mistaken ... In any case, thanks for your help.

+4
source share
1 answer

I think that since the ajax request is asynchronous, you should apply the crossfilter function in the success function. This way you only create and use your cross-filter data after loading ajax data.

0
source

Source: https://habr.com/ru/post/1479953/


All Articles