Plotly.js

3.5.0 · active · verified Sun Apr 19

Plotly.js is an open-source JavaScript data visualization library that provides a wide array of interactive, publication-quality charts and graphs. It is the core engine powering the popular Plotly.py and Plotly.R libraries, offering a unified graphing experience across different programming environments. The library supports dozens of chart types, including statistical, 3D, scientific, SVG/tile maps, and financial charts. It is currently stable at version 3.5.0, with minor releases featuring new attributes, bug fixes, and performance improvements appearing frequently. Its key differentiators include comprehensive chart type support, robust interactivity features, and its foundational role in the broader Plotly ecosystem, enabling complex data narratives in web applications. It can be used as a Node.js module via bundled distributions or directly in the browser via script tags and CDNs.

Warnings

Install

Imports

Quickstart

This example demonstrates how to embed a simple interactive scatter plot using Plotly.js directly in an HTML file via CDN, initializing it with basic data and layout configurations.

<!DOCTYPE html>
<html>
<head>
    <title>Plotly.js Quickstart</title>
    <script src="https://cdn.plot.ly/plotly-3.5.0.min.js" charset="utf-8"></script>
</head>
<body>
    <h1>Simple Plotly.js Chart</h1>
    <div id="myDiv" style="width:600px;height:400px;"></div>

    <script type="text/javascript">
        // Data for the plot
        const trace1 = {
            x: [1, 2, 3, 4],
            y: [10, 15, 13, 17],
            mode: 'markers',
            type: 'scatter',
            name: 'Trace 1'
        };

        const trace2 = {
            x: [1, 2, 3, 4],
            y: [16, 5, 11, 9],
            mode: 'lines+markers',
            type: 'scatter',
            name: 'Trace 2'
        };

        const data = [trace1, trace2];

        // Layout for the plot
        const layout = {
            title: 'My First Plotly.js Graph',
            xaxis: { title: 'X-axis Label' },
            yaxis: { title: 'Y-axis Label' }
        };

        // Create the plot in the div with id 'myDiv'
        Plotly.newPlot('myDiv', data, layout);

        console.log("Plotly chart rendered successfully!");
    </script>
</body>
</html>

view raw JSON →