{"id":13602778,"url":"https://github.com/plotly/plotly-nodejs","last_synced_at":"2025-04-11T13:31:16.901Z","repository":{"id":14165754,"uuid":"16871752","full_name":"plotly/plotly-nodejs","owner":"plotly","description":"node.js wrapper for Plotly's Chart Studio Streaming and REST APIs","archived":false,"fork":false,"pushed_at":"2018-07-29T21:55:14.000Z","size":119,"stargazers_count":168,"open_issues_count":21,"forks_count":76,"subscribers_count":35,"default_branch":"master","last_synced_at":"2024-05-18T00:41:41.336Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://plot.ly/nodejs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plotly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-15T21:04:01.000Z","updated_at":"2024-04-02T17:41:37.000Z","dependencies_parsed_at":"2022-09-10T22:41:36.558Z","dependency_job_id":null,"html_url":"https://github.com/plotly/plotly-nodejs","commit_stats":null,"previous_names":["alexander-daniel/plotly-nodejs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotly%2Fplotly-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotly%2Fplotly-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotly%2Fplotly-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotly%2Fplotly-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plotly","download_url":"https://codeload.github.com/plotly/plotly-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223470262,"owners_count":17150523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T18:01:37.703Z","updated_at":"2024-11-07T06:30:18.369Z","avatar_url":"https://github.com/plotly.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Plotly Node API\n[![Circle CI](https://circleci.com/gh/plotly/plotly-nodejs/tree/master.svg?style=svg)](https://circleci.com/gh/plotly/plotly-nodejs/tree/master)\n\u003e Analyze and Visualize Data, Together\n\n\n## Streaming Plot Examples\n- [mock sensor stream](http://plot.ly/~streaming-demos/6/)\n- [math bar fight](http://plot.ly/~streaming-demos/44/)\n\n## Installation\n```javascript\nnpm install plotly\n```\n\n## Usage\n```javascript\nvar plotly = require('plotly')('username','apiKey');\n\nvar data = [{x:[], y:[], stream:{token:'yourStreamtoken', maxpoints:200}}];\nvar graphOptions = {fileopt : \"extend\", filename : \"nodenodenode\"};\n\nplotly.plot(data,graphOptions,function() {\n  var stream = plotly.stream('yourStreamtoken', function (res) {\n    console.log(res);\n  });\n  someReadableStream.pipe(stream);\n});\n```\n\n#### Full REST API Documentation can be found here: [https://plot.ly/api/rest/](https://plot.ly/api/rest/)\n\nSign up for plotly here: [https://plot.ly/](https://plot.ly/) and obtain your API key and Stream Tokens in your plotly settings: [https://plot.ly/settings](https://plot.ly/settings).\n\n# Methods\n## var plotly = require('plotly')(username, apiKey)\n`username` is a string containing your username\n`apiKey` is a string containing your API key\n```javascript\nvar plotly = require('plotly')('username', 'apiKey');\n```\n\n## plotly.plot(data,graphOptions[, callback])\nPlotly graphs are described declaratively with a data JSON Object and a graphOptions JSON Object.\n`data` is an array of Objects and with each object containing data and styling information of separate graph traces. Docs: [https://plot.ly/api/rest](https://plot.ly/api/rest)  \n`graphOptions` is an Object containing styling options like axis information and titles for your graph. Docs: [https://plot.ly/api/rest](https://plot.ly/api/rest)  \n`callback(err,msg)` where `err` is an error Object, and `msg` is the return response Object\n\nThe `msg` object has the following attributes : `msg.url`,`msg.filename`,`msg.message`,`msg.warning`,`msg.error`\n```javascript\n// examples/rest-example.js\n\nvar plotly = require('plotly')('username','apiKey');\n\nvar data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}];\nvar graphOptions = {fileopt : \"extend\", filename : \"nodenodenode\"};\n\nplotly.plot(data, graphOptions, function (err, msg) {\n    console.log(msg);\n});\n```\n## var stream = plotly.stream(token[, callback])\n`token` accepts a token string\n`callback(res)` where `res` is a the response object with the following attributes : `res.msg`, `res.statusCode`\n\n```javascript\n// examples/streaming-example.js\nvar plotly = require('plotly')('username','apiKey');\n\nvar initData = [{x:[], y:[], stream:{token:'token', maxpoints:200}}];\nvar initGraphOptions = {fileopt : \"extend\", filename : \"nodenodenode\"};\n\nplotly.plot(initData, initGraphOptions, function (err, msg) {\n  if (err) return console.log(err)\n  console.log(msg);\n\n  var stream1 = plotly.stream('token', function (err, res) {\n    console.log(err, res);\n    clearInterval(loop); // once stream is closed, stop writing\n  });\n\n  var i = 0;\n  var loop = setInterval(function () {\n      var streamObject = JSON.stringify({ x : i, y : i });\n      stream1.write(streamObject+'\\n');\n      i++;\n  }, 1000);\n});\n```\n\n[Live Streaming Example](https://plot.ly/~Streaming-Demos/6/)\n```javascript\n// examples/signal-stream.js\n\n/* If you have not signed up for Plotly you can do so using https://plot.ly\n * or see the example signup.js. Once you do, populate the config.json in this\n * example folder!\n */\nvar config = require('./config.json')\n  , username = config['user']\n  , apiKey = config['apiKey']\n  , token = config['token']\n  , Plotly = require('../.')(username, apiKey)\n  , Signal = require('random-signal')\n\n\n// build a data object - see https://plot.ly/api/rest/docs for information\nvar data = {\n    'x':[]   // empty arrays since we will be streaming our data to into these arrays\n  , 'y':[]\n  , 'type':'scatter'\n  , 'mode':'lines+markers'\n  , marker: {\n      color: \"rgba(31, 119, 180, 0.96)\"\n  }\n  , line: {\n      color:\"rgba(31, 119, 180, 0.31)\"\n  }\n  , stream: {\n      \"token\": token\n    , \"maxpoints\": 100\n  }\n}\n\n// build your layout and file options\nvar graphOptions = {\n    \"filename\": \"streamSimpleSensor\"\n  , \"fileopt\": \"overwrite\"\n  , \"layout\": {\n      \"title\": \"streaming mock sensor data\"\n  }\n  , \"world_readable\": true\n}\n\n/*\n * Call plotly.plot to set the file up.\n * If you have included a streaming token\n * you should get a \"All Streams Go!\" message\n */\n\nPlotly.plot(data, graphOptions, function (err, resp) {\n    if (err) return console.log(\"ERROR\", err)\n\n    console.log(resp)\n\n    var plotlystream = Plotly.stream(token, function () {})\n    var signalstream = Signal({tdelta: 100}) //\n\n\n    plotlystream.on(\"error\", function (err) {\n        signalstream.destroy()\n    })\n\n    // Okay - stream to our plot!\n    signalstream.pipe(plotlystream)\n})\n```\n\n\n## plotly.getFigure(fileOwner, fileId[, callback])\n`file_owner` accepts a string of the file owner's name\n`fileId` is an integer, representing the graph ID\n`callback(figure)` where `figure` is a the JSON object of the graph figure\n\n```javascript\nvar plotly = require('plotly')('username','apiKey');\n\nplotly.getFigure('fileOwner', 'fileId', function (err, figure) {\n    if (err) console.log(err);\n    console.log(figure);\n});\n```\n\n## plotly.getImage(figure[, options, callback])\n`figure` is a JSON object of the graph figure\n`options.format` | `jpeg`, `png`, `pdf`, `eps`, `webp`\n`options.width` | width in `px` (default : 700)\n`options.height` | height in `px` (default : 500)\n\n`callback(err, imageData)`  \n\n`err` is an Error Object\n`imageStream` is a Stream of base-64 encoded imageData\n\n```javascript\nvar plotly = require('plotly')('username','apiKey');\nvar fs = require('fs');\n\nvar trace1 = {\n  x: [1, 2, 3, 4],\n  y: [10, 15, 13, 17],\n  type: \"scatter\"\n};\n\nvar figure = { 'data': [trace1] };\n\nvar imgOpts = {\n    format: 'png',\n    width: 1000,\n    height: 500\n};\n\nplotly.getImage(figure, imgOpts, function (error, imageStream) {\n    if (error) return console.log (error);\n\n    var fileStream = fs.createWriteStream('1.png');\n    imageStream.pipe(fileStream);\n});\n```\n\nYou can also use `getFigure()` and `getImage()` together!\n```javascript\nvar plotly = require('../.')('username','apiKey');\n\n// grab the figure from an existing plot\nplotly.getFigure('fileOwner', 'fileId', function (err, figure) {\n\tif (err) return console.log(err);\n\n\tvar imgOpts = {\n\t\tformat: 'png',\n\t\twidth: 1000,\n\t\theight: 500\n\t};\n\n    plotly.getImage(figure, imgOpts, function (error, imageStream) {\n        if (error) return console.log (error);\n\n        var fileStream = fs.createWriteStream('2.png');\n        imageStream.pipe(fileStream);\n    });\n});\n```\n\n## plotly.deletePlot(fid[, callback])\n`fid` is a String, the id of the plot you wish you delete\n`callback` is a function with `err` and `plot` as parameters. `err`, if present, is the error message returned from the request. `plot` is the plot that was deleted.\n\n```javascript\nvar plotly = require('../.')('username','apiKey');\n\nplotly.deletePlot('88', function (err, plot) {\n    if (err) console.log(err)\n    else console.log(plot);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotly%2Fplotly-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplotly%2Fplotly-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotly%2Fplotly-nodejs/lists"}