Show Sidebar Hide Sidebar
Plotly.js

Getting Started in JavaScript

Getting Started with plotly

New to Plotly?

Plotly is a free and open-source graphing library for JavaScript. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

Download

Download the minified plotly.js source code and dependencies.

Include the downloaded scripts before the end of the </head> tag in your HTML document:

<head>
	<script src="plotly-latest.min.js"></script>
</head>

Download plotly.js

plotly.js CDN

You can also use the ultrafast plotly.js CDN link. This CDN is graciously provided by the incredible team at Fastly.

<head>
               <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

Else, if you want to get a specific version of plotly.js, say 1.2.0:

<head>
               <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
</head>

Start plotting!

In your HTML document, create an empty DIV to draw the graph in:

<div id="tester" style="width:600px;height:250px;"></div>

Now you can make interactive plotly.js charts using Plotly.newPlot().

<script>
	TESTER = document.getElementById('tester');
	Plotly.newPlot( TESTER, [{
	x: [1, 2, 3, 4, 5],
	y: [1, 2, 4, 8, 16] }], {
	margin: { t: 0 } } );
</script>

Now you can pass Plotly.newPlot() either the ID of the DIV ("tester") or the DIV DOM element (TESTER).

Webpack user?

For plotly.js to build with Webpack you will need to install ify-loader@v1.1.0+ and add it to your webpack.config.json. This adds Browserify transform compatibility to Webpack which is necessary for some plotly.js dependencies.

A repo that demonstrates how to build plotly.js with Webpack can be found here. In short add ify-loader to the module section in your webpack.config.js:


  ...
      module: {
          rules: [
              {
                  test: /\.js$/,
                  loader: 'ify-loader'
              }
          ]
      },
  ...
          

Hello World Example

plotly.js runs on all SVG-compatible browsers