Below is the workflow I am currently dealing with: 1) The client makes an AJAX call on index.html to select a dataset 2) processor.php generates a new CSV file based on the data obtained from a MySQL query 3) Upon callback in index.html, d3.js uses the dataset from the CSV file to create a graph 4) However, repeating steps 1 to 3 prevents d3 from accessing the most recent CSV file
While I can successfully retrieve the CSV file through d3 upon the initial AJAX call, subsequent calls made by the client do not allow d3 to fetch the latest file. The code seems to be unable to capture the most recent file.
Here is the snippet of code from index.html
$.post( 'processor.php',
$("#queryform :input").serializeArray(),
function(data) {
d3.csv('diagrams/chord.csv', function (error, data) {
var mpr = chordMpr(data);
mpr
.addValuesToMap('chimp')
.setFilter(function (row, a, b) {
return (row.chimp === a.name && row.performedon === b.name)
})
.setAccessor(function (recs, a, b) {
if (!recs[0]) return 0;
return +recs[0].count;
});
sliderbanimate()
drawChords(mpr.getMatrix(), mpr.getMap());
});
This excerpt is just part of the code, but my objective during the AJAX call is for the d3 plugin to utilize the most recent CSV file available
And here is the processor.php script that creates a new CSV file using MySQL during the AJAX call:
$chordquery = mysqli_query($connection, 'SELECT a.CName as CName, a.Performed_on as performed_on,Count(*) as Count
FROM behavior a WHERE
BName IN ('.$behaviourarry.') GROUP BY CName, performed_on');
$num = 0;
while($resultchord = mysqli_fetch_array($chordquery)) {
$rel[$num]['chimp'] = $resultchord['CName'];
$rel[$num]['performedon'] = $resultchord['performed_on'];
$rel[$num]['count'] = $resultchord['Count'];
$num++;
//$data2[] = $row3['CName'];
//echo $row3['CName']."-".$row3['performed_on']."-".$row3['BName']."-".$row3['Year']."-".$row3['Count']."<br/>";
}
$output = fopen("diagrams/chord.csv",'w') or die("Can't open php://output");
//header("Content-Type:application/csv");
//header("Content-Disposition:attachment;filename=pressurecsv.csv");
fputcsv($output, array('chimp','performedon','count'));
foreach($rel as $relation) {
fputcsv($output, $relation);
}
fclose($output) or die("Can't close php://output");
I'm really hoping someone can assist me with this issue...thank you in advance!