Scatter plot with slider

From JSXGraph Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Here is a dynamic scatter plot whose value depend on a slider. See Scatter plot for a static scatter plot.

The underlying JavaScript code

const board = JXG.JSXGraph.initBoard('jxgbox', { 
    boundingbox: [-5, 5, 5, -5], axis:true
});

var slider = board.create('slider', [[-3, 4.5], [3, 4.5], [0,3,5]]);
var scatterplot = board.create('curve', [[], []], {strokeWidth: 3, lineCap: 'round'});

scatterplot.updateDataArray = function() {
	var i, 
      s = slider.Value(); 
  
  this.dataX = [];
  this.dataY = [];
  for (i = 0; i < 1000; i++) {
    x = Math.random() * 8 - 4;
    y = Math.random() * s * 2 - s;
    this.dataX.push(x, x, NaN);
    this.dataY.push(y, y, NaN);
  }
};

board.update();