我正在使用Angular 4开发一个Web应用程序。我基于这个post (Angular 4 with Plotly)成功导入了Plotly.js
plotly.js basic捆绑包可以很好地处理折线图。但是我不能让直方图和二维密度图在typescript中工作。我怀疑我需要导入plotlyjs-cartesian捆绑包。
输出示例

这是我的基于plot.ly/javascript/histograms的component.ts,但是是Typescript。
import * as Plotly from 'plotly.js';
import {
Config,
Data,
Layout
} from 'plotly.js';
@Component({
...
})
export class ChartComponent implements OnInit {
constructor() {}
ngOnInit() {
let x = [];
for (let i = 0; i < 500; i++) {
x[i] = Math.random();
}
const trace = {
x: x,
type: 'histogram',
};
const data = [trace];
Plotly.newPlot('myPlotlyDiv', data);
}
}这是我的tsconfig.app.json "compilerOptions“
"types": [
"plotly.js"
],
"paths": {
"plotly.js": [
"../node_modules/plotly.js/dist/plotly-basic.js"
]
}我曾尝试在plotly-basic.js后面添加"../node_modules/plotly.js/dist/plotly-cartesian.js“,但也不起作用。
对于在这种情况下为直方图、Histogram2d图表导入plotlyjs-cartesian bundle有什么建议吗?
发布于 2018-02-07 02:18:35
我解决了这个问题。我没有使用plotly-basic.min.js包,而是在angular-cli.json和tsconfig.app.json中都使用了plotly.min.js。带有直方图子图的2D直方图轮廓图在Angular 4/5,Typescript代码中出现得很好。
https://stackoverflow.com/questions/48515839
复制相似问题