Display a base64 image of a chart.
I have a simple chart that I create. After it is created i want to take the base64 image of it and display it in html but I am not able to do that.
Here is my FIDDLE
HTML
<body>
<canvas id="chartJSContainer" width="100" height="100"></canvas>
<img src="" id="coolImage" class="img-fluid" alt="Responsive image">
</body>
JS CODE
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1,
backgroundColor: 'rgba(255, 0, 15, 0.54)'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
label: {
fontSize: 50
},
scales: {
yAxes: [{
ticks: {
reverse: false
}
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
var lineChart = new Chart(ctx, options);
document.getElementById('coolImage').setAttribute('src', lineChart.toBase64Image());
I am not even sure if i am logic is correct because there could be a easier way to do this. I essentially want to display the image of the graph rather than the interactive line graph itself.