javascriptd3.jsimportplottable

How to Import Plottable.js


I am fairly new to javaScript. I am having issues finding out how to import and use the Plottalbe.js (along with D3 that is part of it) libraries. Can anyone show me a working example of an HTML and .js file that uses Plottable? I must have severe blindness because I cannot find anything on this.

I used npm and the package was placed into C:\Users\me\node_modules.

Here is what I have tried so far. Excuse my code. I have tried different approaches, and I still fail.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>JavaScript</title>
  <!-- <link     href="https://cdnjs.cloudflare.com/ajax/libs/plottable.js/1.15.0/plottable.css"
    rel="stylesheet" /> -->
  <script src="scripts/require.js"></script>
  <!-- <script     src="https://cdn.jsdelivr.net/npm/plottable@3/plottable.min.js"></script> -->
  <script src="app.js"></script>
</head>
<body>
  <h1>JS</h1>
</body>
</html>

And then the app.js.

//import { Plottable } from "plottable";
// var Plottable = require('plottable');

require(['plottable'], function (plottable) {
// var Plottable = require('plottable');
});

// define(function (require){
// var Plottable = require('plottable');
// });

Solution

  • Add import Plottable from 'plottable'; to the top of your js file (assuming you are using Node). If not, you will need to require your dependency using the full path to the file.