Skip to content

Instantly share code, notes, and snippets.

@teguhn
Created May 3, 2016 17:21
Show Gist options
  • Save teguhn/87b4677f62b4a8e5fc1ad2900c6e7014 to your computer and use it in GitHub Desktop.
Save teguhn/87b4677f62b4a8e5fc1ad2900c6e7014 to your computer and use it in GitHub Desktop.
function getCol(data, colname) {
var x = [];
for (var i = 0; i < data.length; i++) {
x.push(data[i][colname]);
}
return x;
}
function xy(data, x_col, y_col) {
return {
x: getCol(data, x_col),
y: getCol(data, y_col)
};
}
Plotly.d3.csv("https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv", function(data) {
var container = 'myDiv';
var line1 = xy(data, 'AAPL_x', 'AAPL_y');
line1.mode = 'lines+markers';
var outputData = [line1];
var layout = {
title: 'Plotting CSV data from AJAX call',
xaxis: {
title: 'xaxis'
},
yaxis: {
title: 'yaxis'
}
};
Plotly.newPlot(container, outputData, layout);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment