<html>
<head>
<script src="https://29913-45646037-gh.circle-artifacts.com/0/dist/plotly.js"></script>
</head>
<body>
<table>
<tr>
<td>
<div id="chart1" width="800px" height="500px">
</div>
</td>
<td>
<div id="chart2" width="800px" height="500px">
</div>
</td>
</tr>
<tr>
<td>
<div id="chart3" width="800px" height="500px">
</div>
</td>
<td>
<div id="chart4" width="800px" height="500px">
</div>
</td>
</tr>
</table>
<script>
function addEventListeners(graphDiv, hoverColors) {
if (hoverColors) {
graphDiv.on('plotly_hover', function(data){
var update = {};
var prop_name;
if (data.points[0].data.marker.color) {
prop_name = "color";
}
else {
prop_name = "colors";
}
update["marker." + prop_name] = [data.points[0].data.marker[prop_name].map((e, i) => ((i == data.points[0].pointNumber) ? data.points[0].data.marker.colorsHover[i] : e))];
Plotly.restyle(graphDiv, update, data.points[0].curveNumber);
console.log("hover");
});
graphDiv.on('plotly_unhover', function(data){
var update = {};
var prop_name;
if (data.points[0].data.marker.color) {
prop_name = "color";
}
else {
prop_name = "colors";
}
update["marker." + prop_name] = [data.points[0].data.marker[prop_name].map((e, i) => ((i == data.points[0].pointNumber) ? data.points[0].data.marker.colorsUnhover[i] : e))];
Plotly.restyle(graphDiv, update, data.points[0].curveNumber);
console.log("unhover");
});
}
else {
graphDiv.on('plotly_hover', function(data){
console.log("hover");
});
graphDiv.on('plotly_unhover', function(data){
console.log("unhover");
});
}
}
var data1 = [
{
"type": "pie",
"marker": {
"colors": ["#5757E5", "#5596E6", "#01B49F", "#8CD210", "#FDD600", "#9B4FD7", "#FF38A1", "#EA1C2B", "#FF7925", "#5757E5", "#5596E6", "#01B49F"],
"colorsHover": ["#3131BF", "#2F70C0", "#008E79", "#66AC00", "#D7B000", "#7529B1", "#D9127B", "#C40005", "#D95300", "#3131BF", "#2F70C0", "#008E79"],
"colorsUnhover": ["#5757E5", "#5596E6", "#01B49F", "#8CD210", "#FDD600", "#9B4FD7", "#FF38A1", "#EA1C2B", "#FF7925", "#5757E5", "#5596E6", "#01B49F"]
},
"textfont": {
"size": 12
},
"values": [11, 6, 9, 5, 16, 7, 5, 10, 14, 19, 37, 6],
"labels": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"sort": false,
"direction": "clockwise",
"hoverinfo": "label+value+percent",
"textinfo": "percent"
}
];
var layout1 = {
"font": {
"size": 12
},
"showlegend": true,
"height": 500,
"width": 800,
"legend": {
"traceorder": "normal"
},
title: {
"text": "Pie Chart with Hover Highlighting"
},
"hovermode": "closest",
"margin": {
"l": 80,
"r": 80,
"t": 100,
"b": 80
}
};
var layout2 = {
"font": {
"size": 12
},
"showlegend": true,
"height": 500,
"width": 800,
"legend": {
"traceorder": "normal"
},
title: {
"text": "Pie Chart without Hover Highlighting"
},
"hovermode": "closest",
"margin": {
"l": 80,
"r": 80,
"t": 100,
"b": 80
}
};
var data3 = [
{
"type": "bar",
"marker": {
"color": ["#5757E5", "#5596E6", "#01B49F", "#8CD210", "#FDD600", "#9B4FD7", "#FF38A1", "#EA1C2B", "#FF7925", "#5757E5", "#5596E6", "#01B49F"],
"colorsHover": ["#3131BF", "#2F70C0", "#008E79", "#66AC00", "#D7B000", "#7529B1", "#D9127B", "#C40005", "#D95300", "#3131BF", "#2F70C0", "#008E79"],
"colorsUnhover": ["#5757E5", "#5596E6", "#01B49F", "#8CD210", "#FDD600", "#9B4FD7", "#FF38A1", "#EA1C2B", "#FF7925", "#5757E5", "#5596E6", "#01B49F"]
},
"textfont": {
"size": 12
},
"y": [11, 6, 9, 5, 16, 7, 5, 10, 14, 19, 37, 6],
"x": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"sort": false,
"hoverinfo": "x+y"
}
];
var layout3 = {
"font": {
"size": 12
},
"height": 500,
"width": 800,
title: {
"text": "Bar Chart with Hover Highlighting"
},
"hovermode": "closest",
"margin": {
"l": 80,
"r": 80,
"t": 100,
"b": 80
}
};
var graphDiv1 = document.getElementById("chart1");
Plotly.newPlot(graphDiv1, data1, layout1);
addEventListeners(graphDiv1, true);
var graphDiv2 = document.getElementById("chart2");
Plotly.newPlot(graphDiv2, data1, layout2);
addEventListeners(graphDiv2, false);
var graphDiv3 = document.getElementById("chart3");
Plotly.newPlot(graphDiv3, data3, layout3);
addEventListeners(graphDiv3, true);
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |