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

Answer Stackoverlow Question #230

Open jamesleesaunders opened 1 year ago

jamesleesaunders commented 1 year ago

I am trying to plot D3 X3D charts with points. A basic example uses a random set of them. I want to plot data from arrays, how to pass data to the variable "var myData"? For example, I have "1 2 3 4 5, 6 7 8 9 10" for axis variables.

<script>
    // Select chartholder
    var chartHolder = d3.select("#chartholder");

    // Declare the chart component
    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 refreshChart = function() {
      // Generate some data
      var myData = d3.x3d.randomData.dataset6(200);

      chartHolder.datum(myData).call(myChart);
    };

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

    refreshChart();
</script> 

There is a good example for Bar charts. There we have Keys with [] holders. I want to make it here.

From: https://stackoverflow.com/questions/73078754/how-to-load-array-data-into-d3-x3d-charts