0
votes

I found a code to add a label to each value in the Y axis and I have tried it. This is the code

var chart = new Chart(ctx, {
    type: 'line',
    data: data,
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    // Include a dollar sign in the ticks
                    callback: function(value, index, values) {
                        return '$' + value;
                    }
                }
            }]
        }
    }
});

But, can I give it only for minimum and maximum values? If so, how?

The following is an example chart that I mean. The minimum and maximum labels I give a red mark.

Example chart that I mean

Example chart that I mean

1

1 Answers

0
votes

You can specify min and max directly, Please check https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#step-size

e.g

var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
    scales: {
        yAxes: [{
            ticks: {
                // Include a dollar sign in the ticks
                callback: function(value, index, values) {
                    return '$' + value;
                },
             min: 1,
             max: 100
            }
        }]
    }
}});

You can also use axis range settings, It is only change the data values that are used to scale the axis and useful for extending the range of the axis while maintaining the auto fit behaviour. https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#axis-range-settings

e.g.

var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
    scales: {
        yAxes: [{
            ticks: {
                // Include a dollar sign in the ticks
                callback: function(value, index, values) {
                    return '$' + value;
                },
             suggestedMin: 1,
             suggestedMax: 100
            }
        }]
    }
}});