Scatter plot with slider

From JSXGraph Wiki
Revision as of 12:00, 20 April 2020 by A WASSERMANN (talk | contribs) (Created page with "Here is a dynamic scatter plot whose value depend on a slider. See Scatter plot for a static scatter plot. <jsxgraph width="500" height="500"> const board = JXG.JSXGraph....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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});

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();