事实上,这在 JSXGraph 中是不可能开箱即用的。但对于特定的函数图,它应该是可行的。诀窍是有一个处理阴影的进一步图表。
对于抛物线的情况,我们将抛物线的点克隆到着色曲线,并预先添加更多点,使填充区域始终位于曲线下方。这是代码:
var left = -5, right = 5, top = 5, bot = -5;
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [left, top, right, bot], axis:true
});
var a = board.create('slider', [[-4,4],[3,4],[-10,1,10]], {name:'a'});
var b = board.create('slider', [[-4,3.5],[3,3.5],[-10,1,10]], {name:'b'});
var c = board.create('slider', [[-4,3],[3,3],[-10,1,10]], {name:'c'});
var graph = board.create('functiongraph', [
function (x) { return (a.Value() * x * x + b.Value() * x + c.Value()); }
], { strokeColor: 'black', highlightStrokeColor: 'yellow', strokeWidth: 2});
// Add a second curve for the filling
var g1 = board.create('curve', [[], []],
{fillColor: 'yellow', fillOpacity: 0.2});
// This is the update function for the second curve
g1.updateDataArray = function() {
var i, le = graph.numberPoints;
this.dataX = [];
this.dataY = [];
// Add the lower left corner of the board
this.dataX.push(left);
this.dataY.push(bot);
if (graph.points[0].usrCoords[1] > left) {
this.dataX.push(left);
this.dataY.push(top);
}
// Add the points of the original curve
for (i = 0; i < le; i++) {
this.dataX.push(graph.points[i].usrCoords[1]);
this.dataY.push(graph.points[i].usrCoords[2]);
}
// Add the lower right corner of the board
if (graph.points[le - 1].usrCoords[1] < right) {
this.dataX.push(right);
this.dataY.push(top);
}
this.dataX.push(right);
this.dataY.push(bot);
};
// An update of the board is mandatory to show the filling immediately.
board.update();
在https://jsfiddle.net/7retmajL/上查看它的实际应用。