I am using Chart.js 2.0 version to draw graphs, i want to define minimum step size in bar graph
var myNewChart = new Chart(grapharea, { type: 'bar', data: barData, options: { responsive: true, scales: { yAxes: [ { ticks: { min: 0, // it is for ignoring negative step. beginAtZero: true, stepSize: 1 // if i use this it always set it '1', which look very awkward if it have high value e.g. '100'. } } ] } } });
this time i am using
stepSize: 1
i am using this step size to ignore the point value e.g. '0.5', it shows when the max graph values id less e.g '2'.
if i use this it always set the step it '1', which look very awkward if it have high value e.g. '100'.
I am looking for such thing: suggestedMin = 1
Is there any thing to define thie minimum step size which should not be fixed in higher value cases.
Step Size. If set, the scale ticks will be enumerated by multiple of stepSize , having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm. This example sets up a chart with a y axis that creates ticks at 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5 .
Chart. js provides a selection of ready to go charts which can be styled and configured while D3 offers building blocks which are combined to create virtually any data visualisation.
Chart. js still uses the HTML Canvas element, so charts generated with it look blurred when printed or zoomed in. Nowadays I prefer Apexcharts. js, which renders to SVG.
Chart. js charts are rendered on user provided canvas elements. Thus, it is up to the user to create the canvas element in a way that is accessible.
If you don't want to show point value (e.g. 0.5) labels you could write a callback function to filter the point value labels instead of using stepSize.
Like this:
ticks: { min: 0, // it is for ignoring negative step. beginAtZero: true, callback: function(value, index, values) { if (Math.floor(value) === value) { return value; } } }
Working fiddle here: https://jsfiddle.net/ma7h611L/
As noted by Atta H. and Lekoaf below, Chart.js added the precision property to ticks. It is available since version 2.7.3. See Lekoaf's answer how to use this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With