forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Candlestick can now be combined with a bar chart without axis rescale…
… problem.
- Loading branch information
1 parent
585dbe5
commit 830ea58
Showing
9 changed files
with
125 additions
and
110 deletions.
There are no files selected for viewing
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,51 @@ | ||
var numTraces = 20; // 10 | ||
var numCats = 25; // 15 | ||
var initialUpdates = 15; // 5 | ||
|
||
var catBaseName = "THIS_IS_A_VERY_VERY_VERY_VERY_VERY_VERY_LONG_CATEGORY_BASE_NAME"; | ||
var yMin = -100; | ||
var yMax = 100; | ||
var plotDiv; | ||
var timesUpdated = 0; | ||
var interval = 1000; | ||
var clearHandle; | ||
|
||
// Categories and indices are the same for everyone | ||
var categories = []; | ||
for (var c = 1; c <= numCats; c++) { | ||
categories.push(c + "_" + catBaseName + "_" + c); | ||
} | ||
var updatedIndices = []; | ||
for (var t = 0; t < numTraces; t++) { | ||
updatedIndices.push(t); | ||
var trace1 = { | ||
//x: [2, 3, 4], | ||
//y: [-40, 50, 60], | ||
x: ['2017-01-04', '2017-01-05', '2017-01-06'], | ||
y: [-40, 50, 60], | ||
close: [116.019997, 116.610001, 117.910004], | ||
|
||
decreasing: {line: {color: '#7F7F7F'}}, | ||
|
||
high: [116.510002, 116.860001, 118.160004], | ||
|
||
increasing: {line: {color: '#17BECF'}}, | ||
|
||
line: {color: 'rgba(31,119,180,1)'}, | ||
|
||
low: [115.75, 115.809998, 116.470001], | ||
|
||
open: [115.849998, 115.919998, 116.779999], | ||
|
||
type: 'candlestick', | ||
name: 'candlestick', | ||
opacity: 0.5 | ||
}; | ||
|
||
function updateData() { | ||
var updatedData = { | ||
y: [] | ||
}; | ||
|
||
for (var t = 0; t < numTraces; t++) { | ||
var yValues = []; | ||
for (var v = 0; v < numCats; v++) { | ||
var val = yMin + Math.random() * (yMax - yMin); | ||
yValues.push(val); | ||
} | ||
updatedData.y.push(yValues); | ||
} | ||
|
||
Plotly.restyle(plotDiv, updatedData, updatedIndices); | ||
|
||
timesUpdated++; | ||
} | ||
var trace2 = { | ||
//x: [2, 3, 4], | ||
x: ['2017-01-04', '2017-01-05', '2017-01-06'], | ||
y: [21, 5, 6], | ||
name: 'yaxis2 data', | ||
yaxis: 'y2', | ||
type: 'bar', | ||
opacity: 0.3 | ||
}; | ||
|
||
function generateChart() { | ||
var traces = []; | ||
for (var t = 1; t <= numTraces; t++) { | ||
var trace = { | ||
type: 'bar', | ||
x: categories, | ||
y: [], | ||
name: "Trace " + t | ||
} | ||
for (var v = 0; v < numCats; v++) { | ||
trace.y.push((yMin + yMax) / 2); | ||
} | ||
traces.push(trace); | ||
var data = [trace2, trace1]; | ||
|
||
var layout = { | ||
title: 'Double Y Axis Example', | ||
yaxis: {title: 'yaxis title'}, | ||
yaxis2: { | ||
title: 'yaxis2 title', | ||
titlefont: {color: 'rgb(148, 103, 189)'}, | ||
tickfont: {color: 'rgb(148, 103, 189)'}, | ||
overlaying: 'y', | ||
side: 'right' | ||
} | ||
}; | ||
|
||
var layout = { | ||
barmode: 'group', | ||
hovermode: 'closest', | ||
// xaxis: { | ||
// showticklabels: false | ||
// }, | ||
// yaxis: { | ||
// showticklabels: false | ||
// } | ||
}; | ||
plotDiv = document.getElementById('myDiv'); | ||
|
||
Plotly.newPlot(plotDiv, traces, layout, {displayModeBar: false}); | ||
updateData(); | ||
|
||
plotDiv.addEventListener('click', function () { | ||
updateData(); | ||
}, true); | ||
} | ||
|
||
var plotDiv = document.getElementById('myDiv'); | ||
|
||
function handleTheClick() { | ||
window.event.target.innerHTML = ""; | ||
generateChart(); | ||
clearHandle = window.setInterval(function () { | ||
if (timesUpdated < initialUpdates) { | ||
updateData(); | ||
} else { | ||
window.clearInterval(clearHandle); | ||
// plotDiv.innerHTML = "<h1 style='position: absolute; top: 50%; left: 50%; font-size: 100px; transform: translate(-50%, -50%);'>COMPLETED</h1>"; | ||
} | ||
}, interval); | ||
} | ||
// document.addEventListener('DOMContentLoaded', function() { | ||
// generateChart(); | ||
// }, false); | ||
Plotly.newPlot(plotDiv, data, layout); |
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
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
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
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