简体   繁体   中英

How to set up Plotly.js for WebStorm?

I'm working on a website using JavaScript (first time I've tried). I need a graph for it and am using Plotly.js. However, I am getting messages such as "Unresolved method or function" for require() and "'var' used instead of 'let' or 'const'", in addition to the program saying Plotly isn't imported.

Could someone help me out with where I'm going wrong or direct me to a source that may help me work this out?

<head>
    <meta charset="UTF-8">
    <!-- Include Plotly.js --><script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    <title> IOT webpage w/real time graph </title>
</head>

<script>
    var plotly = require('plotly')("jhharvey", "••••••••••")

    var trace = {
        x: [1, 2, 3, 4, 5, 6, 7, 8],
        y: [1, 4, 9, 16, 25, 36, 49, 64],
        mode: 'line'
    };

    var data = [ trace ];
    Plotly.newPlot('myDiv', data);
  1. to get require() and other Node.js core methods resolved, please make sure to enable Coding assistance for Node.js in Settings | Languages & Frameworks | Node.js and NPM

  2. to get rid of "'var' used instead of 'let' or 'const'" warnings, either disable the JavaScript | ECMAScript 6 migration aids | 'var' used instead of 'let' or 'const' inspection in Settings | Editor | Inspections or change Javascript Language version to ECMAScript 5.1 in Settings | Languages & Frameworks | JavaScript

Note that Plotly.newPlot('myDiv', data); should be Plotly.plot('myDiv', data); (there is no newPlot() method in Plotly, as far as i can check). And you need changing the case in variable name - you import the module as plotly and then refer to it as Plotly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM