I am trying to replace points of a scatter plot with a PNG image. Based on the documentation, the pointStyle
accepts either a string or an image. However instead of the image on the first point, it just shows a regular scatter plot point. Any ideas?
var ctx = document.getElementById("myChart").getContext('2d');
var img = new Image();
var img1 = img.src = 'assets/img/small/STORM.png';
var imageData = {
datasets: [{
pointStyle: [img1, 'rect', 'triangle', 'circle'],
data: [{
x: 1.447377,
y: -0.014573
}, {
x: 2.365398,
y: -1.062847
}, {
x: -2.507778,
y: 0.389309
}, {
x: -0.432636,
y: 0.124841
}]
}]
}
var myChart = new Chart(ctx, {
type: 'scatter',
data: imageData,
options: {}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.min.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
You can see a working example in jsfiddle here