Coder Social home page Coder Social logo

mbejda / plotlychartexport Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 775 KB

Export Plot.ly charts on the server

Home Page: https://www.npmjs.com/package/plotlychartexport

License: MIT License

JavaScript 97.13% HTML 2.87%
plotly chart nodejs plotlyjs charts

plotlychartexport's Introduction

Plot.ly Chart Export

PlotlyChartExport uses Phantom.js to render plot.ly charts on the server. It crops the chart, base64 encodes it and returns the encoded chart in a resolving promise. It does not rely on the filesystem nor does it rely on graphics libraries like Cairo making it an effective chart rendering solution for serverless environments.

  • Only 1 Dependency
  • Works in Serverless Environments
  • Size < 10MB

Installation

npm install plotlychartexport --save

Usage

/// include library
const exp = require('plotlychartexport');

/// define plot.ly data properties
let trace1 = {
    x: [1, 2, 3, 4],
    y: [10, 15, 13, 17],
    type: 'scatter'
};
let trace2 = {
    x: [1, 2, 3, 4],
    y: [16, 5, 11, 9],
    type: 'scatter'
};

/// define plot.ly layout
let layout = {
    title: 'Line and Scatter Plot'
};

/// run render command
exp.render([trace1, trace2], layout).then((base) => {
    console.log(base); /// base64
}, (error) => {
    console.error(error);
})

Create a Serverless Chart Export

Checkout this tutorial I made on how to create serverless chart exports on AWS to see the module in action. https://www.mbejda.com/creating-serverless-plotly-chart-exports

If you are experiencing any issues with this module open up a ticket and send me a tweet. @notMiloBejda

plotlychartexport's People

Contributors

mbejda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

studyeverything

plotlychartexport's Issues

Able to render charts client side just fine, when I try to export to the base64 image its returning null in my success

I followed the readme exactly as you laid it out, even with your sample data. No matter what I pass to the exp.render function, it always hits my .then but the param its passing back is always empty. If i console log, it returns nothing... if i upload it to s3 its a 0kb image. Any ideas on what would cause this? I'm assuming something is messing up when phantomjs is trying to grab me an image but if there was an error caused from phantomjs i would assume the render function wouldnt resolve?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.