admin管理员组

文章数量:1336631

There are two packages plotly.js and plotly.js-dist.

What is the difference between them and which one should I use?

Moreover on npmjs on plotly.js page it says in order to install plotly.js one have to run:

npm install plotly.js-dist

I mean, I can see that plotly.js is a project with many files, and that plotly.js-dist is a bundle, just one file. But I don't get why it is distributed like this.

Especially, that plotly.js-dist is not minified, and in plotly.js there is minified file, which I guess can be used in order to import this library to one's project.

There are two packages plotly.js and plotly.js-dist.

What is the difference between them and which one should I use?

Moreover on npmjs on plotly.js page it says in order to install plotly.js one have to run:

npm install plotly.js-dist

I mean, I can see that plotly.js is a project with many files, and that plotly.js-dist is a bundle, just one file. But I don't get why it is distributed like this.

Especially, that plotly.js-dist is not minified, and in plotly.js there is minified file, which I guess can be used in order to import this library to one's project.

Share Improve this question edited Jan 15, 2019 at 13:59 matvs asked Jan 15, 2019 at 13:46 matvsmatvs 1,87317 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

These files are same. I checked and pared.

If you using npm + typescript(+Angular), I remend to use option , npm install plotly.js-dist.
If you using npm(or not) + javascript, I remend to use option 3 with plotly.min.js.

Don't mention minified or not. Because after bundling every module minified.
So, it's up to you which file need to see via developer tool while debugging.

Here is Quick start options.

  1. Install with npm : npm install plotly.js-dist.
  • Ready-to-use plotly.js distributed bundle.
  • Contains trace modules, visit here
  1. Use the plotly.js CDN hosted by Fastly.
  2. Download the latest release : plotly.js or plotly.min.js. More info here.

It doesn't matter what you choose but it is different slightly how to bundle/deploy your project.
And using definition file. @types/plotly.js
For further information from here, check Bundle information section.

Also, if you work with angular? here is another option : angular-plotly.js.


This is my answer for your second phrase.
"plotly.js" is hard to set it up for bundling. Here is what I've done with this and my goal was:

  1. Working on angular2-seed with Angular 4.
  2. Fully defined each type/interface.

Step 1. Install package.

Change mand, thanks @Jesse

npm install plotly.js-dist --save
npm install @types/plotly.js --save-dev
npm install @types/d3 --save-dev

Note: @types/d3 is dependency of @types/plotly.js. but if you don't need it, remove it from index.d.ts.

Step 2. rename folder to use definition file.

Rename folder "plotly.js" to "plotly.js-dist" in "node_modules/@types".

Update - 9/12/2023

This is my env;

  • windows 11(x64)
  • Node v18.17.1
  • Angular 13.2.0

I remend as below,

npm i --save plotly.js-dist-min
npm i --save-dev @types/plotly.js-dist-min

This is little bit different between official guide.

import { Component, ElementRef, ViewChild, OnInit, AfterViewInit } from '@angular/core';
import * as Plotly from 'plotly.js-dist-min';

@Component({ ... })
export class AppComponent implements OnInit, AfterViewInit {  
  myData!: Partial<Plotly.PlotData>[];
  @ViewChild('chart') div?: ElementRef;

  ngOnInit(): void {
    this.myData = [
      {
        x: ['giraffes', 'orangutans', 'monkeys'],
        y: [20, 14, 23],
        type: 'bar',
      },
    ];
  }

  ngAfterViewInit(): void {
    const element = this.div?.nativeElement;
    Plotly.newPlot(element, this.myData);
  }
}

本文标签: javascriptShould I install plotlyjs or plotlyjsdist via npmStack Overflow