chart.js - Chartjs: How to create padding between ticks and scale label -


i'm using chartjs-node create graph, , use label y-axis.

my problem distance between y-axes ticks , label minimal , not good. i've gone on docs , couldn't find useful scenario... there's option under options -> scales -> yaxes -> ticks -> padding doesn't give desired effect.

currently have workaround under options -> scales -> yaxes -> ticks -> callback manually insert spaces: callback: (val) => ` ${val}%`

this works, not correct usage, , believe if scale linear approach prohibit me using of features available linear scale.

anyone knows how can create separation between ticks , label in more elegant way?

this can achieved using afterfit callback function of y-axis :

scales: {    yaxes: [{       afterfit: function(scale) {          scale.width = 80 //<-- set value wish        },       ...    }] } 

ɪɴ ᴀᴄᴛɪᴏɴ

var chart = new chart(ctx, {     type: 'line',     data: {        labels: ['jan', 'feb', 'mar'],        datasets: [{           label: 'line',           data: [3, 2, 4],           backgroundcolor: 'rgba(0, 119, 290, 0.2)',           bordercolor: 'rgba(0, 119, 290, 0.6)'        }]     },     options: {        responsive: false,        scales: {           yaxes: [{              afterfit: function(scale) {                 scale.width = 80  //<-- set value wish               },              scalelabel: {                 display: true,                 labelstring: 'y-axis label',              }           }]        }     }  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.6.0/chart.min.js"></script>  <canvas id="ctx" height="180"></canvas>


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -