In JavaScript I want to plot a function using function-plot. In the end I want to plot a complex function and not just a one-line function. Here is the code:
var parameters = {
target: '#myFunction',
data: [{
fn: function(scope) {
return scope.x;
},
color: 'red',
closed: false
}],
grid: true,
yAxis: {
domain: [0, 24]
},
xAxis: {
domain: [0, 365]
}
};
function plot() {
var alpha = 23; // a parameter later taken from a html element and to be used in the function.
// I need to replace the actual function each time I change parameters later.
// This is just a simple example.
parameters.data[0].fn = function(scope) {
v = alpha * Math.sin(scope.x / 300);
console.log(v);
return v;
};
functionPlot(parameters);
}
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://mauriciopoppe.github.io/function-plot/js/function-plot.js"></script>
<body onload="plot();"></body>
but when running this code the only output are many NaN's. What am I doing wrong here?