I'm using Chart.js
to draw a graph.
Here is the structure of my code :
<div id="graph_slider">
<div class="row">
<div id="first_container" class="col-md-6">
<canvas id="my_graph"></canvas>
</div>
<div id="second_container" class="col-md-6"></div>
</div>
</div>
<button type="button" id="clone">Clone graph</button>
<script>
var ctx = document.getElementById('my_graph').getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Item 1', 'Item 2', 'Item 3'],
datasets: [{data: [10, 20, 30]}]
}
});
$("#clone").click(function(){
//clone the graph...
});
</script>
What I would like to do is to "clone" the graph #my_graph
and append it to the div #second_container
so that I could have the exact same graphs side-by-side when I click the button #clone.
Does someone know how to do this please?