For more info about plotlyjs, refer to our online documentation page.
Last active
August 29, 2015 14:27
-
-
Save etpinard/b74432ea2aa0e972e11b to your computer and use it in GitHub Desktop.
Reproduce a plotly graph on the plotly cloud using plotlyjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plotlyjs reproduce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/237913/jquery-2.1.4.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.5/d3.js"></script> | |
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/237913/plotly.min.js"></script> | |
</head> | |
<body> | |
<div style="width: 100%; overflow: hidden;"> | |
<div id="plot1" style="width: 500px; float: left;"></div> | |
<div id="plot2" style="margin-left: 500px;"></div> | |
</div> | |
<script src="./main.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global Plotly:false, d3:false */ | |
(function() { | |
// example taken from: | |
// https://plot.ly/javascript-graphing-library/bar-charts/#stacked-bar-chart | |
var plotUrlusingJSON = 'https://plot.ly/~PlotBot/38.json'; | |
d3.json(plotUrlusingJSON, function(err, fig) { | |
fig.layout.title = 'made from a plotly cloud json'; | |
Plotly.plot('plot1', fig.data, fig.layout); | |
}); | |
var plotUrlusingCSV = 'https://plot.ly/~PlotBot/38.csv'; | |
d3.csv(plotUrlusingCSV, function(err, dataCSV) { | |
var x = [], | |
y1 = [], | |
y2 = []; | |
dataCSV.forEach(function(p) { | |
x.push(p['x']); | |
y1.push(p['SF Zoo']); | |
y2.push(p['LA Zoo']); | |
}); | |
var data = [ | |
{ | |
type: 'bar', | |
x: x, | |
y: y1, | |
name: 'SF Zoo' | |
}, | |
{ | |
type: 'bar', | |
x: x, | |
y: y2, | |
name: 'LA Zoo' | |
} | |
]; | |
var layout = { | |
title: 'made from plotly cloud csv', | |
barmode: 'stack', | |
width: 500, | |
height: 500 | |
}; | |
Plotly.plot('plot2', data, layout); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment