Hi. This is my first time on this forum. I want to generate scatter plots in Chart.js. I understand that this requires an array of objects containing (x,y) pairs. I wrote a function that returns such an array, and it works fine. What I want to do is generate this data array with its object elements from a set of (x,y) coordinate values, rather than writing out the entire array as is done now in the function. For now, I would be happy to generate the values from a random number generator, with later the ability to pass the X and Y values as input parameters to the function. Can anyone help?
function generateDataPairs() {
var i;
var pairs=[
{ x: -9.3, y: 0.5 },{ x: 0.5, y: 9.3 }, { x: 3.9, y: 8.9 },
{ x: 1, y: 4.7 },{ x: 9, y: 1.3 },{ x: -1, y: 5 }
];
return pairs;
}
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
// The type of chart we want to create
type: 'scatter',
data: {
datasets: [{
label: 'Scatter Data',
data: generateDataPairs(),
showLine:true,fill:false,
tension:0
}]
},