score:2
I was trying to accomplish this in a Vue app (built with Webpack), and landed on the following solution. Import an image and create an image element like so:
import myIcon from '@/assets/my-icon.svg'
const chartPoint = new Image()
chartPoint.src = myIcon
Then in your chart.js dataset options (adjust to your needs):
{
data: data,
pointRadius: 10,
borderWidth: 0,
pointStyle: chartPoint,
...
}
drawImage() takes various types of image elements, but the easiest is just an HTMLImageElement, which you can create in your markup or with Javascript, as above.
score:7
Here is a more complete example. It shows how you can set styles for individual points or for all points.
var yourImage = new Image()
yourImage.src ='http://your.site.com/your_image.png';
var imageData = {
labels: ['one', 'two', 'three', 'four'],
datasets: [{
label: 'Label1',
pointRadius: [10, 0, 10, 10],
pointHoverRadius: 20,
pointHitRadius: 20,
pointStyle: ['rect', yourImage, 'triangle', 'circle'],
pointBackgroundColor: "rgba(0,191,255)",
data: [1.5, 2.3, 3, 2.5]
}]
}
window.onload = function() {
var lineID = document.getElementById('canvas').getContext('2d');
var lineChart = new Chart(lineID, {
type: 'line',
data: imageData,
options: {}
});
score:11
var yourImage = new Image(),
yourImage.src ='http://your.site.com/your_image.png';
data = {
labels: ['one', 'two', 'three'],
datasets: [{
label: 'Label1',
pointRadius: [0,0,0,0,20],
pointHoverRadius: [0,0,0,0,20],
pointHitRadius: [0,0,0,0,20],
pointStyle: ['', '', '', '', yourImage],
data: [1,2,3]
}, {
label: 'label2',
pointRadius: [0,0,0,0,20],
pointHoverRadius: [0,0,0,0,20],
pointHitRadius: [0,0,0,0,20],
pointStyle: ['', '', '', '', yourImage],
data: [1,2,3]
}]
Source: stackoverflow.com
Related Query
- Chart.js Custom Image for Each Point
- Add a text as tooltip for each point on a line chart
- How can I create custom tooltips for each data point in a graph?
- Chartjs Custom Legend for Doughnut Chart Having Labelled Lines Sticking Out of Each Section
- Chartjs random colors for each part of pie chart with data dynamically from database
- chart.js Line chart with different background colors for each section
- Different color for each column in angular-chartjs bar chart
- Can I specify a different font size for each row of text in Chart Title?
- chart js - Apply different color for each x-axes label
- chartjs custom y axis values, different text for each one
- Chart JS pass in custom data for points
- How to wait for all items to load within ng-repeat before then rendering a chart for each item
- How to use set the color for each bar in a bar chart using chartjs?
- Empty circle - only point strok in line chart for ChartJS
- Get Value for point clicked on Pie Chart in Chart.js 3
- How to set X coordinate for each bar with react chart js 2?
- Issue with chartjs linear gradient for the mixed bar chart in ReactJS is not calculated for each individual Bars
- Chart.JS - Tooltips - Issue: 3 data points, all three individual tooltips showing for each data point
- How do I get a different label for each bar in a bar chart in ChartJS?
- ChartJS/High Charts Radar chart - Different radial axis labels for each category that appear on hover
- Charts JS: Doughnut chart and hiding tooltip for specific data index within each dataset
- Chart.js How can I embed additional values to each data point in radar chart
- Can chart.js display text associated with each point on a line chart that is permanently visible?
- Charts.js - How to set custom tooltip text for each dataset
- ChartJS: Custom legend not showing Labels for Multi-Pie chart
- Show label for every data point in line chart
- Plugin for custom horizontal line Y-axis marker on grid of a Line chart with Chart.js
- How to custom index label on each bar chart using chartjs?
- getting additional value fields from data source for dx.chartjs doughnut chart
- subcategories for each bar in multibar chart using chartjs
More Query from same tag
- Inserting and Fetching values from mongodb using nodejs and chartjs
- How to fill the gaps in an array of Dates with fixed length
- Angular Chartjs Overlapping Bar Chart with Chartjs ver 2.7
- Chart js: how can I align the legend and the title
- Cannot zoom in Chart.js
- Create bar chart with chart.js where space per bar is the same, overall chart size adjusted
- How to change the time format displayed in the chart?
- The dataset in ng2 charts for bar graph is not setting properly
- How to append more data in tooltip of graph in chart.js
- ChartJS - why is there a visual difference when displaying the same dataset alone or with more datasets?
- How to order tooltip values from the biggest to the smallest
- Chartjs: Double x axis not having the same gridline
- Chart.js - Shift/Stagger labels horizontally (for x axis) instead of rotating
- Chart.js V2.7.2 How to make Horizontal scroll bar without loosing Y-Axis
- show xAxes on click
- How to hide / not draw bars with 0 / null / undefined values?
- How to set min Value a step down of min value received from database in Y Axis in ChartJS
- How to put labels at 4 points of the day?
- Hiding Chart.js line, but showing it's data in the tooltip
- Failing to render chart – "can't acquire context from the given item"
- Adding data to charts.js dynamically from tables
- How to create Chart with 2 variables (x,,y)
- How to use Chart.js with Typescript without getting assignable errors?
- How do I make the Line in ChartJS not exceed the maximum of yAxes
- Pausing Javascript animation on minimize
- I am getting TS2339: Property 'chart' does not exist on type 'Window'?
- Align rotated text to left of canvas
- How to show text likt this in Chartjs Dougnet chart
- Chartjs v7.0 with plugin zoom, strange effect when use "drag" mode.
- Plotting firebase data to ChartJS