Chartjs react horizontal bar chart change y axis labels to images

56 views Asked by At

In this chart I want to replace the text labels "January", "February", etc. with images:

enter image description here

How can I do this with Chart.js and React chart js 2? I cannot see this document in the documentation.

CodeSandbox

1

There are 1 answers

0
furkan çöker On

If you want to write months on bars you can use ChartDataLabels plugins and formatter.

 plugins: [ChartDataLabels],
    options: {
        indexAxis: "y",
        plugins: {
          datalabels: {
            color: "#fff",
            anchor: "center",
            align: "center",
            font: {
              size: 16,
            },
            formatter: function (value, context) {
              return months[context.dataIndex];
            },
          },
        },
      },

this will you give something like this

months on text label