Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@etpinard
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etpinard/b74432ea2aa0e972e11b to your computer and use it in GitHub Desktop.
Save etpinard/b74432ea2aa0e972e11b to your computer and use it in GitHub Desktop.
Reproduce a plotly graph on the plotly cloud using plotlyjs
plotlyjs reproduce

For more info about plotlyjs, refer to our online documentation page.

<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>
/* 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