javascript - 在 Angular 中导入 Plotly.js

标签 javascript typescript plotly

我按照此 SO answer 中的说明进行操作巧妙地集成到应用程序中。

不幸的是,在尝试 plotly.js 的标准示例时,我遇到了 typescript 错误。 Plotly.newPlot(...) 的参数类型似乎不正确。

enter image description here

这是我的组件:

import {Component, OnInit} from '@angular/core';
import * as Plotly from 'plotly.js';
import {Config, Data, Layout} from 'plotly.js';

@Component({
  selector: 'app-tabs',
  templateUrl: './tabs.component.html',
  styleUrls: ['./tabs.component.css']
})
export class TabsComponent implements OnInit {

  constructor() {
  }

  ngOnInit() {
    let y0 = [];
    let y1 = [];
    for (var i = 0; i < 50; i++) {
      y0[i] = Math.random();
      y1[i] = Math.random() + 1;
    }
    var trace1 = {
      y: y0,
      type: 'box'
    };
    let trace2 = {
      y: y1,
      type: 'box'
    };

    let data = [trace1, trace2];
    Plotly.newPlot('myDiv', data);
  }
}

我使用 plotly.js@1.37.1 和 angular v6.0.0

最佳答案

您不需要将 Plotly 放入 angular.json 中,只需像这样导入即可。

import * as Plotly from 'plotly.js/dist/plotly.js';
import {Config, Data, Layout} from 'plotly.js/dist/plotly.js';

关于javascript - 在 Angular 中导入 Plotly.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50213078/

相关文章:

javascript - 如何在分层 SVG 出现在视口(viewport)上时激活其动画?

javascript - 刷新页面时 HTML 5 Web SQL 数据库事务提交或回滚

typescript - 选择器找不到测试 Controller

c# - 如何正确地将文件从 ASP.NET Core 下载到 Angular?

python - 无法将甘特图放入破折号

python - 绘图图表上的辅助/平行 X 轴 (python)

javascript - 根据json值生成表格单元格中的图表

javascript - 需要帮助使用 Javascript 获取要填充的字段

javascript - 包含多个文件和其他输入字段的表单验证

angular - 如何将 Firebase Querysnapshot 转换为对象数组