score:1

Accepted answer

if you want to change all the points label color use the option pointlabelfontcolor.

if you want to change points label color individually you have to change chart.js since it does not implement this feature.

here are the chart.js modifications needed to achieve change points label color individually:

change chart.js lines:

from:

ctx.fillstyle = this.pointlabelfontcolor;

to:

ctx.fillstyle = this.labels[i].fillstyle;

and

from:

ctx.filltext(this.labels[i], pointlabelposition.x, pointlabelposition.y);

to:

ctx.filltext(this.labels[i].text, pointlabelposition.x, pointlabelposition.y);

and

from:

textwidth = this.ctx.measuretext(template(this.templatestring, { value: this.labels[i] })).width + 5;

to:

textwidth = this.ctx.measuretext(template(this.templatestring, { value: this.labels[i].text })).width + 5;

your html should be:

<html>
<head>
    <title>radar chart - example</title>
    <script type="text/javascript" src="chartjs/chart.js"></script>
</head>

<body>
    <canvas id="mychart" width="400" height="400"></canvas>

    <script>

        var data = {
            labels: [{
                text: "eating", 
                fillstyle: "#01a4e0"
            }, {
                text: "drinking", 
                fillstyle: "#ffe897"
            }, {
                text: "sleeping", 
                fillstyle: "#428e2a"
            }, {
                text: "designing", 
                fillstyle: "#6b3a0d"
            }, {
                text: "coding", 
                fillstyle: "#0d5e6b"
            },{
                text: "cycling", 
                fillstyle: "#450d6b"
            },{
                text: "running", 
                fillstyle: "#6b0d36"
            }],         

            datasets: [{
                label: "my first dataset",
                fillcolor: "rgba(220,220,220,0.2)",
                strokecolor: "rgba(220,220,220,1)",
                pointcolor: "rgba(220,220,220,1)",
                pointstrokecolor: "#fff",
                pointhighlightfill: "#fff",
                pointhighlightstroke: "rgba(220,220,220,1)",
                data: [65, 59, 90, 81, 56, 55, 40]
            }, {
                label: "my second dataset",
                fillcolor: "rgba(151,187,205,0.2)",
                strokecolor: "rgba(151,187,205,1)",
                pointcolor: "rgba(151,187,205,1)",
                pointstrokecolor: "#fff",
                pointhighlightfill: "#fff",
                pointhighlightstroke: "rgba(151,187,205,1)",
                data: [28, 48, 40, 19, 96, 27, 100]
            }]
        };      

        var ctx = document.getelementbyid('mychart').getcontext('2d');
        var myradarchart = new chart(ctx).radar(data);

    </script>
</body>
</html>

if you use the same chart.js for other radar charts that would still use labels as arrays you can add support for both ways of setting labels (array and object) replacing the mentioned chart.js lines using these instead:

ctx.fillstyle = this.labels[i].fillstyle ? this.labels[i].fillstyle : this.pointlabelfontcolor;


ctx.filltext((this.labels[i].text ? this.labels[i].text : this.labels[i]), pointlabelposition.x, pointlabelposition.y);


textwidth = this.ctx.measuretext(template(this.templatestring, { value: (this.labels[i].text ? this.labels[i].text : this.labels[i]) })).width + 5;

score:7

based on chart.js 2.7 documentation we may color labels with options.scale.pointlabels.fontcolor :

        let tagslabel = [ 'axe1', 'axe2', 'axe3'];
        let chart = new chart(targetnode, {
            type: 'radar',
            data: {
                labels: tagslabel,
                datasets: [
                    {
                        data: [
                            0, 2,
                        ],
                    }
                ]
            },
            options: {
                responsive: true,
                legend: {
                    position: 'left'
                },
                title: {
                    display: true,
                    text: "it work's"
                },
                animation: {
                    animatescale: true,
                    animaterotate: true
                },
                scale: {
                    // ticks: {
                    //     backdropcolor: 'red',
                    //     // include a dollar sign in the ticks
                    //     callback: function(value, index, values) {
                    //         return '$' + value;
                    //     }
                    // }
                    pointlabels: {
                        // callback: function(value, index, values) {
                        //     return '$' + value;
                        // }
                        fontcolor: tagslabel.map((lbl)=>randcolor()),
                    },
                },
            }
        });

Related Query

More Query from same tag