Chartjs-How do I override the function convertTicksToLabels chartjs

0👍

I found an different way to map values to strings without using the function.

I used the callback key instead of the convertTicksToLabels function.

Here is my code now…

      chart = new Chart(ctx, {
        type: 'bubble',
        data: dataObj,
        options: {
            scales: {
                yAxes: [{ 
                    ticks:{
                        display: true,
                        callback: function(value, index, values) {
                            return mapValtoString(value);
                        }
                    },
                    scaleLabel: {labelString: "Factualness"},
                    gridLines:{display:false}
                }],
                xAxes: [{ 
                    ticks:{display: false},
                    scaleLabel: {labelString: "Bias"},
                    gridLines:{display:false}
                }]
              }
        }
    });

The mapValToString() function looks like this…

function mapValtoString(val){
    switch(val){
        case 1:
            return "LOW";
            break;
        case 2:
            return "MEDIUM";
            break;
        case 3:
            return "HIGH";
            break;  
        default:
            return "";
    }

I return the string I want associated with a value and a blank string on the values not needed.

This solved my problem, the graph now displays strings instead of number values.

Leave a comment