Copy OrgChart JS JSON Data to Clipboard with Ctrl+C and paste it anywhere you need
When building interactive org charts, it’s often useful to quickly copy the chart data — for debugging, exporting, or sharing with a teammate.
With OrgChart JS, you can easily do this using a simple keyboard shortcut: Ctrl + C.
In this tutorial, we’ll add a small JavaScript snippet that listens for the key press and copies the current chart data to the clipboard in JSON format.
🧩 Step 1. Include OrgChart JS
Add the library from CDN and create a container for your chart.
<script src="https://cdn.balkan.app/orgchart.js"></script>
<div id="tree"></div>
⚙️ Step 2. Initialize the Chart
Here’s a small chart example with three nodes:
let chart = new OrgChart(document.getElementById("tree"), {
mode: 'dark',
mouseScrool: OrgChart.action.scroll,
nodeBinding: {
field_0: "name"
}
});
chart.load([
{ id: 1, name: "Denny Curtis" },
{ id: 2, pid: 1, name: "Ashley Barnett" },
{ id: 3, pid: 1, name: "Caden Ellison" }
]);
⌨️ Step 3. Add the Ctrl + C Copy Shortcut
Now we’ll listen for the Ctrl + C key combination.
When pressed, we’ll take the chart data, convert it to JSON, and copy it to the clipboard.
document.addEventListener("keydown", function (e) {
if (e.ctrlKey && e.key.toLowerCase() === "c") {
e.preventDefault();
const data = chart.config.nodes;
const json = JSON.stringify(data, null, 2);
const textarea = document.createElement("textarea");
textarea.value = json;
textarea.style.position = "fixed";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
}
});
✅ Step 4. Try It Live
You can test the full working example here:
👉 Code Example: Copy to Clipboard
Press Ctrl + C and check your console — you’ll see a confirmation message, and your chart’s JSON data will be in your clipboard, ready to paste anywhere.