我正在使用允许数据可视化的数据分析工具 (KNIME),但只能通过公开 javascript 层(即我无法构建 html 文件),因此这意味着我需要通过 Requirejs 加载外部库。我通常只使用 d3.js 库,它通过 require() 函数加载非常简单。但是,当我尝试加载回归 js 库时,回归对象返回为未定义。Regression-js Github 页面供参考 - https://github.com/Tom-Alexander/regression-js如何加载这两个库,以便正确可视化我的数据?我试过弄乱 shim() 和 define() 但我不确定我哪里出错了。require.config({ paths: { d3src: 'https://d3js.org', }, map: { '*': { 'd3': 'd3src/d3.v5.min', //loads fine 'd3-color': 'd3src/d3-color.v1.min', //loads fine 'd3-interpolate': 'd3src/d3-interpolate.v1.min', //loads fine 'd3-scale-chromatic': 'd3/src/d3-scale-chromatic.v1.min', //loads fine 'regression': 'https://cdnjs.cloudflare.com/ajax/libs/regression/1.4.0/regression.min.js' //does not seem to load properly } }});require(['d3', 'd3-color', 'd3-interpolate','regression'], function(d3,regression) { //am I not calling the regression object correctly here?//ideally this code should return somethingconst result = regression.linear([[0, 1], [32, 67], [12, 79]]);// Uncaught TypeError: regression.linear is not a functionconst gradient = result.equation[0];const yIntercept = result.equation[1];console.log(result,gradient,yIntercept);});在提供的代码中,console.log() 应该返回一个对象,后跟两个浮点数。
添加回答
举报
0/150
提交
取消