score:0
According to Chart.js documentation, pointStyle
is either a string
or an Image
but not an array.
If you want to have individual styles for your points, you can use the Plugin Core API. It offers several hooks that may be used for executing custom code. You could use the afterDraw
hook to assign a different pointStyle
to each point.
plugins: {
afterUpdate: function(chart) {
const meta = chart.getDatasetMeta(0);
meta.data[0]._model.pointStyle = img;
meta.data[1]._model.pointStyle = 'rect';
meta.data[2]._model.pointStyle = 'triangle';
meta.data[3]._model.pointStyle = 'circle';
}
},
I your amended code below, I used a slightly different but more compact approach and defined the pointStyles
array outside of the chart configuration.
const img = new Image();
img.src = 'https://i.stack.imgur.com/gXQrT.png';
const pointStyles = [img, 'rect', 'triangle', 'circle'];
new Chart(document.getElementById('myChart'), {
type: 'scatter',
plugins: {
afterUpdate: chart => {
chart.getDatasetMeta(0).data.forEach((d, i) => d._model.pointStyle = pointStyles[i]);
}
},
data: {
datasets: [{
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}
],
backgroundColor: ['white', 'green', 'red', 'orange'],
pointRadius: 10
}]
},
options: {
legend: {
display: false
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<canvas id="myChart" height="90"></canvas>
Source: stackoverflow.com
Related Query
- Show image instead a point in a ChartJS scatter plot
- chartjs show dot point on hover over line chart
- How to add ChartJS code in Html2Pdf to view image
- ChartJs Force scatter plot to be square shaped
- Using chartjs v2 to show categorical values on axis instead of numeric
- First point on scatter plot on JavaScript chart.js not showing
- Scatter plot not showing anything chartjs needs some debugging
- Chart.js point format data for a scatter plot
- React ChartJS Scatter Plot - cannot plot the data
- plot a point on top on line chart in chartjs
- How to create a scatter plot where x-axis represents a day by hours with datetime object? chartJS
- ChartJS scale ticks with scatter plot
- how to add color to each data in chartjs scatter plot
- Is There any way to show image on top of the stacked bar, Am getting image on every color Instead of that i need only on top of each bar
- Show and plot zero values on ChartJS line graph when no data
- ChartJS Scatter plot with JSON list variable not working
- ChartJS - Different color per data point
- how to change size of point in ChartJS
- ChartJs 2.0 How do I obtain point information being clicked upon?
- how to plot multiple time series in chartjs where each time series has different times
- Adding Image inside Linechart points in ChartJs
- chart.js scatter chart - displaying label specific to point in tooltip
- Show bar with zero value in ChartJs v2
- Chartjs hide data point labels
- Chartjs linechart with only one point - how to center
- In Chart.js I want to show dotted gridLines like in below image
- show label in tooltip but not in x axis for chartjs line chart
- Chart.js Custom Image for Each Point
- ChartJS Line Graph - Multiple Lines, Show one Value on Tooltip
- Chartjs + jsPDF = Blurry image
More Query from same tag
- Charts.js rendering issue on page load
- How to remove all gridlines and ticks all lines in lines chart in javascript taken from cdn)
- ChartJS - Returning labels and data from server on different calls
- Chart.js Doughnut with rounded edges
- Display point style on legend in chart.js
- Right way to Plot Dynamic Grouped Bar chart.js
- Is there any way to use 2 different color for the same bar in a chart?
- Page break in Angular with Chartjs and tables
- Hide labels on x-axis ChartJS
- How to solve a Chart.js 2.0 issue with mouseover and several updates?
- Access data arrays from c# method inside JavaScript inside .cshtml file
- ChartJS - Uncaught SyntaxError: Unexpected number
- Get access to the chart.js component instance in React
- Is it Possible to get the base 64 of graph without showing it on page / canvas (Graph.Js)
- How can I hide a chartjs chart?
- I am trying to use the Chartjs-plugin-watermark but it is not working
- How do I create multiple charts at the same page with angular?
- Can't figure out how to skip first datapoint on the x-axis and labels on X-axis skip second-to-last datapoint with Chart.js
- Customizing ChartJS.org
- Chart.js on Angular with @types/chart.js
- How to fix chart not starting at zero
- Vertical Gird Line Issue with Chart.js
- Chart.JS: How can I only display data labels when the bar width is big enough for the text?
- How can I display the percentage symbol inside the chartjs?
- Problem extending data series in Chart.js
- Pausing Javascript animation on minimize
- End x-axis on last data point (scatter plot) for x,y numeric values
- ChartJs chart won't update new values
- Chart.js - How to display all bars as different datasets(same behaviour as doughnut)
- chart js date range picker apply function