4

I have a chart which designed based on a mock-up but the the mock-up chart has used custom icons for legends pointStyles which basically i couldn't find them in chart JS itself, i tried different classes of pointStyle like ('rect', 'clearRect') but it all have different styles. so basically my question is how can we give custom icons/design for charts pointStyle.

Mockup chart:

enter image description here

My chart:

enter image description here

My Chart JS:

new Chart(document.getElementById("report-chart"), {
    type: 'line',
    data: {
        labels: chartData.label,
        datasets: [{
            label: 'FMV INSTALLED',
            data: chartData.data.fmvI,
            borderColor: "#69bd45",
            fill: false,
            borderWidth: 2,
            pointStyle: 'clearRect'

        }, {
            label: 'EXCHANGE',
            data: chartData.data.fmv,
            borderColor: "#f18e35",
            borderDash: [2, 2],
            fill: false,
            pointStyle: 'rect'

        }, {
            label: 'ORDERLY',
            data: chartData.data.olv,
            borderColor: "#a62061",
            fill: false,
            // borderWidth: 20,
        }, {
            label: 'FORCED',
            data: chartData.data.flv,
            borderColor: "#64cdf3",
            fill: false,
            borderWidth: 1,
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    // Include a dollar sign in the ticks
                    callback: function(value, index, values) {
                        return '$' + value;
                    }
                }
            }],
            xAxes: [{
                position: 'top'
            }]
        },
        legend: {
            display: true,
            position: 'bottom',
            labels: {
                useLineStyle: true,
                usePointStyle: true
            }
        },
    }
});
4
  • Does this answer your question? Change Chartjs Legend Icon Style
    – Awais
    Commented Feb 18, 2020 at 7:24
  • @Awais as you can see the they used classes itself that chart has, i want to set custom icons not from the classes chart provide Commented Feb 18, 2020 at 7:27
  • Try it by giving your custom classNames to pointStyle and define those classes in a CSS file that have a background-image property referring to your icons. datasets: [{ pointStyle: {cutomClassName} }] I have not tried this but it could work. I hope it does! Commented Feb 18, 2020 at 8:45
  • @PrakharMittal thanks from your response, But it didnt work! Commented Feb 18, 2020 at 9:29

0

Browse other questions tagged or ask your own question.