jamesleesaunders / d3-x3d

3D Data Driven Charting Library with D3 and X3D
https://jamesleesaunders.github.io/d3-x3d/
GNU General Public License v2.0
110 stars 22 forks source link

Request example using fetched data #221

Open keithpjolley opened 2 years ago

keithpjolley commented 2 years ago

Can you create an example that uses fetched data? I'm trying to do something like:

var myChart = d3.x3d.chart.scatterPlot()
    .mappings({ x: 'x', y: 'y', z: 'z', size: 'size', color: 'color' })
    .colors(d3.schemeRdYlGn[8])
    .sizeRange([0.1, 1.5]);

var chartHolder = d3.select("#chartholder");

const refreshChart = () => {
    var myData = d3.x3d.randomData.dataset6(200);
    chartHolder.datum(myData).call(myChart);
};

d3.select("#refresh").attr("onclick", "refreshChart2()");
refreshChart();

d3.json('data1.json').then((data) => {
    //refreshChart();
}).catch(() => {
    console.log('fail');
});

but I can't figure out why the above works but if I comment out the first refreshChart() and uncomment out the second it fails.

keithpjolley commented 2 years ago

And yes I'm aware that the refreshChart() doesn't actually use the data I'm pulling. I wanted to eliminate that as a source of error.