Adding Image inside Linechart points in ChartJs

I'm developing a project using ChartJs. I am trying to add icon image inside the line chart instead of points.

I'm attaching an image in which I demonstrate the above requirements. In that image, there is a ChartJs image and a reference image. I would like to add an image inside the line chart of ChartJs exactly like in the reference image(sun and cloud icon).

Chart examples

Is it possible in ChartJs?



As said in the Chart.js line chart data structure (pointStyle attribute) :

String, Array< String >, Image, Array< Image >
The style of point. Options are 'circle', 'triangle', 'rect', 'rectRot', 'cross', 'crossRot', 'star', 'line', and 'dash'. If the option is an image, that image is drawn on the canvas using drawImage.

So you just need to edit your chart and put an image instead of the default circle in the pointStyle attribute of a specific data.

You can do it using Chart.js plugins like this :

// Variables 'sun' and 'cloud' are created before with `new Image()`

    afterUpdate: function(chart) {[0]._meta[0].data[7]._model.pointStyle = sun;[1]._meta[0].data[2]._model.pointStyle = cloud;

And will give you this result.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.